-
Notifications
You must be signed in to change notification settings - Fork 0
/
autohotkey.ahk
executable file
·142 lines (121 loc) · 4.6 KB
/
autohotkey.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
; vim: sw=4 ts=4 et
#Requires AutoHotkey v2.0+
#SingleInstance Force ; The script will Reload if launched while already running
SetWorkingDir(A_ScriptDir)
; Basic Key map
; #: Win
; +: Shift
; ^: Ctrl
; !: Alt
; Volume Up/Down
F5::
{
SoundSetVolume "+5"
}
F4::
{
SoundSetVolume "-5"
}
F3::{
IsMuted := SoundGetMute()
if IsMuted {
SoundSetMute false
} else {
SoundSetMute true
}
}
; Window Swticher
; Path to the DLL, relative to the script
VDA_PATH := A_AppData . "\AutoHotkey\VirtualDesktopAccessor.dll"
hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", VDA_PATH, "Ptr")
GetDesktopCountProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetDesktopCount", "Ptr")
GoToDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GoToDesktopNumber", "Ptr")
GetCurrentDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetCurrentDesktopNumber", "Ptr")
IsWindowOnCurrentVirtualDesktopProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "IsWindowOnCurrentVirtualDesktop", "Ptr")
IsWindowOnDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "IsWindowOnDesktopNumber", "Ptr")
MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "MoveWindowToDesktopNumber", "Ptr")
IsPinnedWindowProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "IsPinnedWindow", "Ptr")
GetDesktopNameProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetDesktopName", "Ptr")
SetDesktopNameProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "SetDesktopName", "Ptr")
CreateDesktopProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "CreateDesktop", "Ptr")
RemoveDesktopProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "RemoveDesktop", "Ptr")
; On change listeners
RegisterPostMessageHookProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "RegisterPostMessageHook", "Ptr")
UnregisterPostMessageHookProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "UnregisterPostMessageHook", "Ptr")
; Util Func
GetDesktopCount() {
global GetDesktopCountProc
count := DllCall(GetDesktopCountProc, "Int")
return count
}
MoveCurrentWindowToDesktop(number) {
global MoveWindowToDesktopNumberProc, GoToDesktopNumberProc
activeHwnd := WinGetID("A")
DllCall(MoveWindowToDesktopNumberProc, "Ptr", activeHwnd, "Int", number, "Int")
}
SetDesktopName(num, name) {
global SetDesktopNameProc
OutputDebug(name)
name_utf8 := Buffer(1024, 0)
StrPut(name, name_utf8, "UTF-8")
ran := DllCall(SetDesktopNameProc, "Int", num, "Ptr", name_utf8, "Int")
return ran
}
; Main Func
MoveCurrentWindowToPrevDesktop() {
global GetCurrentDesktopNumberProc, GoToDesktopNumberProc
current := DllCall(GetCurrentDesktopNumberProc, "Int")
last_desktop := GetDesktopCount() - 1
; If current desktop is 0, do nothing
if (current != 0) {
MoveCurrentWindowToDesktop(current - 1)
}
return
}
MoveCurrentWindowToNextDesktop() {
global GetCurrentDesktopNumberProc, GoToDesktopNumberProc
current := DllCall(GetCurrentDesktopNumberProc, "Int")
last_desktop := GetDesktopCount() - 1
; If current desktop is last, do nothing
if (current != last_desktop) {
MoveCurrentWindowToDesktop(current + 1)
}
return
}
SetDesktopName(0, "Win1 - 🐱")
SetDesktopName(1, "Win2 - 🐱🐱")
SetDesktopName(2, "Win3 - 🐱🐱🐱")
SetDesktopName(3, "Win4 - 🐱🐱🐱🐱")
SetDesktopName(4, "Win5 - 🐱🐱🐱🐱")
#h::#^Left
#l::#^Right
#+h::
{
Send "#^{Left}"
MoveCurrentWindowToPrevDesktop()
}
#+l::
{
Send "#^{Right}"
MoveCurrentWindowToNextDesktop()
}
; DllCall(RegisterPostMessageHookProc, "Ptr", A_ScriptHwnd, "Int", 0x1400 + 30, "Int")
; OnMessage(0x1400 + 30, OnChangeDesktop)
; OnChangeDesktop(wParam, lParam, msg, hwnd) {
; Critical(1)
; OldDesktop := wParam + 1
; NewDesktop := lParam + 1
; Name := GetDesktopName(NewDesktop - 1)
;
; ; Use Dbgview.exe to checkout the output debug logs
; OutputDebug("Desktop changed to " Name " from " OldDesktop " to " NewDesktop)
; ; TraySetIcon(".\Icons\icon" NewDesktop ".ico")
; }
#HotIf WinActive("alacritty")
^+v::
{
A_Clipboard := StrReplace(A_Clipboard, "`r`n", "`n")
Send("^+v")
}
return
#HotIf