Skip to content

Instantly share code, notes, and snippets.

@AlickH
Last active November 6, 2021 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlickH/09a21bd4b882eecd6e6a2ca63869e6e3 to your computer and use it in GitHub Desktop.
Save AlickH/09a21bd4b882eecd6e6a2ca63869e6e3 to your computer and use it in GitHub Desktop.
My AutoHotKey Scripts
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#singleinstance force
#Persistent ; Keeps script running persisitantly
Menu, Tray, Tip, % "Alfred"
Menu, Tray, Icon, % "shell32.dll", 127
Menu, Tray, NoStandard
Menu, Tray, Add, Pause, PauseScript
Menu, Tray, Add, Reload, ReloadScript
Menu, Tray, Add, Exit, ExitScript
;-------------------------------------
;ShareClipboard
;-------------------------------------
;#^v::
;FileRead, Clipboard, *P65001 C:\Users\A.Lick\Desktop\clipboard.txt
;Send, ^v
;-----------------------------------
;HotCorners
;-----------------------------------
IsCorner(cornerID)
{
WinGetPos, X, Y, Xmax, Ymax, Program Manager ; get desktop size
MouseGetPos, MouseX, MouseY ; Function MouseGetPos retrieves the current position of the mouse cursor
T = 5 ; adjust tolerance value (pixels to corner) if desired
CornerTopLeft := (MouseY < T and MouseX < T) ; Boolean stores whether mouse cursor is in top left corner
CornerTopRight := (MouseY < T and MouseX > Xmax - T) ; Boolean stores whether mouse cursor is in top right corner
CornerBottomLeft := (MouseY > Ymax - T and MouseX < T) ; Boolean stores whether mouse cursor is in bottom left corner
CornerBottomRight := (MouseY > Ymax - T and MouseX > Xmax - T) ; Boolean stores whether mouse cursor is in top left corner
if (cornerID = "TopLeft"){
RButtonIsDown := false
return CornerTopLeft
}
else if (cornerID = "TopRight"){
return CornerTopRight
}
else if (cornerID = "BottomLeft"){
return CornerBottomLeft
}
else if (cornerID = "BottomRight") {
return CornerBottomRight
}
}
SetTimer, ShowSpaces, 200
SetTimer, ShowApps, 200
SetTimer, LockScreen, 1000
SetTimer, ShowDesktop, 200
return
ShowSpaces:
CoordMode, Mouse, Screen
if IsCorner("TopLeft")
{
Send, {LWin down} {tab down}
send, {LWin up} {tab up}
Loop
{
if ! IsCorner("TopLeft")
break ; exits loop when mouse is no longer in the corner
}
}
return
ShowApps:
CoordMode, Mouse, Screen
if IsCorner("TopRight")
{
Send, {LWin down}
Send, {LWin up}
Loop
{
if ! IsCorner("TopRight")
break ; exits loop when mouse is no longer in the corner
}
}
return
LockScreen:
CoordMode, Mouse, Screen
if IsCorner("BottomLeft")
{
DllCall("user32.dll\LockWorkStation")
Loop
{
if ! IsCorner("BottomLeft")
break ; exits loop when mouse is no longer in the corner
}
}
return
ShowDesktop:
CoordMode, Mouse, Screen
if IsCorner("BottomRight")
{
Send, {LWin down}{d down}
Send, {LWin up}{d up}
Loop
{
if ! IsCorner("BottomRight")
break ; exits loop when mouse is no longer in the corner
}
}
return
;-------------------------------
;CapsLockSwitch
;-------------------------------
Capslock::
KeyWait, Capslock
if (A_TimeSinceThisHotkey<300)
LayoutSwitch()
else
CapsToggle()
return
CapsToggle() {
if (GetKeyState("CapsLock", "T")==True)
{
SetCapsLockState, off
return True
}
else if (GetKeyState("CapsLock", "T")==False)
{
SetCapsLockState, on
Return True
}
Return False
}
LayoutSwitch(){
Send {LShift Down}
Send {LShift Up}
}
;-----------------------------------------
;SwitchSpaces&Volume&Brightness
;-----------------------------------------
MouseIsOver(WinTitle) {
MouseGetPos,,, Win
return WinExist(WinTitle . " ahk_id " . Win)
}
AdjustScreenBrightness(step) {
service := "winmgmts:{impersonationLevel=impersonate}!\\.\root\WMI"
monitors := ComObjGet(service).ExecQuery("SELECT * FROM WmiMonitorBrightness WHERE Active=TRUE")
monMethods := ComObjGet(service).ExecQuery("SELECT * FROM wmiMonitorBrightNessMethods WHERE Active=TRUE")
minBrightness := 5 ; level below this is identical to this
for i in monitors {
curt := i.CurrentBrightness
break
}
if (curt < minBrightness) ; parenthesis is necessary here
curt := minBrightness
toSet := curt + step
if (toSet > 100)
return
if (toSet < minBrightness)
toSet := minBrightness
for i in monMethods {
i.WmiSetBrightness(1, toSet)
break
}
}
WheelUp::
if MouseIsOver("ahk_class Shell_TrayWnd")
Send {LWin down} {Ctrl down} {left down} {LWin up} {Ctrl up} {left up}
else
mouseGetPos,x,y
if (x>A_ScreenWidth * 0.99) && !MouseIsOver("ahk_class Shell_TrayWnd")
Send {Volume_Up 5}
if (x<A_ScreenWidth * 0.01) && !MouseIsOver("ahk_class Shell_TrayWnd")
AdjustScreenBrightness(10)
else
Send {WheelUp}
Return
Return
WheelDown::
if MouseIsOver("ahk_class Shell_TrayWnd")
Send {LWin down} {Ctrl down} {right down} {LWin up} {Ctrl up} {right up}
else
mouseGetPos,x,y
if (x>A_ScreenWidth * 0.99) && !MouseIsOver("ahk_class Shell_TrayWnd")
Send {Volume_Down 5}
if (x<A_ScreenWidth * 0.01) && !MouseIsOver("ahk_class Shell_TrayWnd")
AdjustScreenBrightness(-10)
else
Send {WheelDown}
Return
Return
#If MouseIsOver("ahk_class Shell_TrayWnd")
MButton::
Send {Volume_Mute}
Return
;-------------------------------------
;Menu
;-------------------------------------
PauseScript:
Pause, Toggle, 1
Return
ReloadScript:
Reload
Return
ExitScript:
ExitApp
Return
#SingleInstance Force
;#NoTrayIcon
#Persistent
Menu, Tray, Tip, % "Toggle Light/Dark Mode"
Menu, Tray, Icon, % "shell32.dll", 26
Menu, Tray, NoStandard
;Menu, Tray, Add, Pause, PauseScript
Menu, Tray, Add, Reload, ReloadScript
Menu, Tray, Add, Exit, ExitScript
SetTimer, CheckTime, 5000
SPI_SETDESKWALLPAPER = 0x0014
CheckTime:
RegRead,L_LightMode,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,SystemUsesLightTheme
TheTime = %A_Hour%%A_Min%
If !(L_LightMode)
If (TheTime < 1800) && (TheTime > 0700)
{
RegWrite,Reg_Dword,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,SystemUsesLightTheme,1
RegWrite,Reg_Dword,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,AppsUseLightTheme ,1
; DllCall( "SystemParametersInfo"
; , "uint", SPI_SETDESKWALLPAPER
; , "uint", 0
; , "str", "C:\Users\A.Lick\Pictures\Camera Roll\Aqua.jpg"
; , "uint", 0 )
return
}
else
{
Return
}
else
If (TheTime < 1800) && (TheTime > 0700)
{
Return
}
else
{
RegWrite,Reg_Dword,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,SystemUsesLightTheme,0
RegWrite,Reg_Dword,HKCU,SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize,AppsUseLightTheme ,0
; DllCall( "SystemParametersInfo"
; , "uint", SPI_SETDESKWALLPAPER
; , "uint", 0
; , "str", "C:\Users\A.Lick\Pictures\Camera Roll\Dark.jpg"
; , "uint", 0 )
return
}
run,RUNDLL32.EXE USER32.DLL`, UpdatePerUserSystemParameters `,2 `,True
Run, %windir%\System32\RUNDLL32.EXE user32.dll`,UpdatePerUserSystemParameters
Return
PauseScript:
Pause, Toggle, 1
Return
ReloadScript:
Reload
Return
ExitScript:
ExitApp
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment