-
Notifications
You must be signed in to change notification settings - Fork 93
/
example.ah2
149 lines (135 loc) · 5.69 KB
/
example.ah2
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
143
144
145
146
147
148
149
; AutoHotkey v2 script
SetWorkingDir(A_ScriptDir)
; Path to the DLL, relative to the script
VDA_PATH := A_ScriptDir . "\target\debug\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")
GetDesktopCount() {
global GetDesktopCountProc
count := DllCall(GetDesktopCountProc, "Int")
return count
}
MoveCurrentWindowToDesktop(number) {
global MoveWindowToDesktopNumberProc, GoToDesktopNumberProc
activeHwnd := WinGetID("A")
DllCall(MoveWindowToDesktopNumberProc, "Ptr", activeHwnd, "Int", number, "Int")
DllCall(GoToDesktopNumberProc, "Int", number, "Int")
}
GoToPrevDesktop() {
global GetCurrentDesktopNumberProc, GoToDesktopNumberProc
current := DllCall(GetCurrentDesktopNumberProc, "Int")
last_desktop := GetDesktopCount() - 1
; If current desktop is 0, go to last desktop
if (current = 0) {
MoveOrGotoDesktopNumber(last_desktop)
} else {
MoveOrGotoDesktopNumber(current - 1)
}
return
}
GoToNextDesktop() {
global GetCurrentDesktopNumberProc, GoToDesktopNumberProc
current := DllCall(GetCurrentDesktopNumberProc, "Int")
last_desktop := GetDesktopCount() - 1
; If current desktop is last, go to first desktop
if (current = last_desktop) {
MoveOrGotoDesktopNumber(0)
} else {
MoveOrGotoDesktopNumber(current + 1)
}
return
}
GoToDesktopNumber(num) {
global GoToDesktopNumberProc
DllCall(GoToDesktopNumberProc, "Int", num, "Int")
return
}
MoveOrGotoDesktopNumber(num) {
; If user is holding down Mouse left button, move the current window also
if (GetKeyState("LButton")) {
MoveCurrentWindowToDesktop(num)
} else {
GoToDesktopNumber(num)
}
return
}
GetDesktopName(num) {
global GetDesktopNameProc
utf8_buffer := Buffer(1024, 0)
ran := DllCall(GetDesktopNameProc, "Int", num, "Ptr", utf8_buffer, "Ptr", utf8_buffer.Size, "Int")
name := StrGet(utf8_buffer, 1024, "UTF-8")
return name
}
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
}
CreateDesktop() {
global CreateDesktopProc
ran := DllCall(CreateDesktopProc, "Int")
return ran
}
RemoveDesktop(remove_desktop_number, fallback_desktop_number) {
global RemoveDesktopProc
ran := DllCall(RemoveDesktopProc, "Int", remove_desktop_number, "Int", fallback_desktop_number, "Int")
return ran
}
; SetDesktopName(0, "It works! 🐱")
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")
}
; #^!+1::MoveOrGotoDesktopNumber(0)
; #^!+2::MoveOrGotoDesktopNumber(1)
; #^!+3::MoveOrGotoDesktopNumber(2)
; #^!+4::MoveOrGotoDesktopNumber(3)
; #^!+5::MoveOrGotoDesktopNumber(4)
; #^!+q::MoveOrGotoDesktopNumber(5)
; #^!+w::MoveOrGotoDesktopNumber(6)
; #^!+e::MoveOrGotoDesktopNumber(7)
; #^!+r::MoveOrGotoDesktopNumber(8)
; #^!+t::MoveOrGotoDesktopNumber(9)
; #^!+x::MoveOrGotoDesktopNumber(10)
; #^!+c::MoveOrGotoDesktopNumber(11)
; #^!+v::MoveOrGotoDesktopNumber(12)
; #^!+b::MoveOrGotoDesktopNumber(13)
F13 & 1:: MoveOrGotoDesktopNumber(0)
F13 & 2:: MoveOrGotoDesktopNumber(1)
F13 & 3:: MoveOrGotoDesktopNumber(2)
F13 & 4:: MoveOrGotoDesktopNumber(3)
F13 & 5:: MoveOrGotoDesktopNumber(4)
F13 & q:: MoveOrGotoDesktopNumber(5)
F13 & w:: MoveOrGotoDesktopNumber(6)
F13 & e:: MoveOrGotoDesktopNumber(7)
F13 & r:: MoveOrGotoDesktopNumber(8)
F13 & t:: MoveOrGotoDesktopNumber(9)
F13 & x:: MoveOrGotoDesktopNumber(10)
F13 & c:: MoveOrGotoDesktopNumber(11)
F13 & v:: MoveOrGotoDesktopNumber(12)
F13 & b:: MoveOrGotoDesktopNumber(13)
F14 UP:: GoToPrevDesktop()
F15 UP:: GoToNextDesktop()