-
Notifications
You must be signed in to change notification settings - Fork 1
/
LokiMaster-Lite.ahk
269 lines (259 loc) · 6.37 KB
/
LokiMaster-Lite.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
; ///////////////////////////////////////////
; An enhencement for Logi Master 3 like mouse
; The lite version without mods, osd & config
; AutoHotkey 1.1.33.10 / Win11 21H2 22000.348
; ///////////////////////////////////////////
; ///////
; Compile
; ///////
;@Ahk2Exe-SetMainIcon %A_ScriptDir%/res/1/1.ico
; /////////
; Privilege
; /////////
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try ; leads to having the script re-launching itself as administrator
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}
; ////////////
; Environments
; ////////////
#NoEnv
;#Warn
#Persistent
#SingleInstance force
#UseHook
SendMode Input
SetWorkingDir %A_ScriptDir%
; ///////
; Globals
; ///////
global app_Name = "Loki Master Lite" ; This is Used by Autorun & Msgbox
global app_Version = "0.21.1228"
global desktop_Count = 1 ; Will be Updated by desktop_Update()
global desktop_Current = 1 ; Current desktop
; /////////
; Tray Menu
; /////////
Menu, Tray, NoStandard
Menu, Tray, Tip, %app_Name% %app_Version%
Menu, Tray, Add , Autorun, menuAutorun
Menu, Tray, Add , Suspend, menuSuspend
Menu, Tray, Add , Reload, menuReload
Menu, Tray, Add , Exit, menuExit
Menu, Tray, Default, Exit
; ////
; Main
; ////
SetKeyDelay, 75
autorun_Check()
SetTimer, mode_WatchDog, 600
; /////
; Mouse
; /////
XButton1:: ; Cycle Desktops
{
desktop_SwitchByCycle()
}
XButton2::Send #d
WheelLeft::Volume_Up
WheelRight::Volume_Down
; OutputDebug, [MODE] User: %mode_User%
; ////////
; Keyboard
; ////////
; Desktop Control
+#1:: desktop_SwitchByNumber(1)
+#2:: desktop_SwitchByNumber(2)
+#3:: desktop_SwitchByNumber(3)
+#4:: desktop_SwitchByNumber(4)
+#5:: desktop_SwitchByNumber(5)
+#6:: desktop_SwitchByNumber(6)
+#7:: desktop_SwitchByNumber(7)
+#8:: desktop_SwitchByNumber(8)
+#9:: desktop_SwitchByNumber(9)
+#NumpadAdd:: desktop_Create()
+#NumpadSub:: desktop_Delete()
; Media Control
AppsKey & Up::Volume_Up
AppsKey & Down::Volume_Down
AppsKey & Left::Media_Prev
AppsKey & Right::Media_Next
AppsKey & Enter::Media_Play_Pause
; Swtich Appskey & RAlt
AppsKey::Ralt
RAlt::AppsKey
; /////////
; Menu Subs
; /////////
; Autorun
menuAutorun:
if autorun_Check() {
autorun_Disable() ; Check/Uncheck this Menu in autorun_Check()
}
Else {
autorun_Enable()
}
Return
; Suspend
menuSuspend:
if A_IsSuspended {
Suspend OFF
Menu, Tray, UnCheck, Suspend
}
Else {
Suspend On
Menu, Tray, Check, Suspend
}
Return
; Reload
menuReload:
Reload
Return
; Exit
menuExit:
MsgBox, 36, %app_Name%, Are you sure to Exit?
IfMsgBox Yes
ExitApp
Return
; /////////////
; Sub Functions
; /////////////
; Watchdog for Desktop
mode_WatchDog() {
static lastDesktop = 0
; Virtual Desktop
desktop_Update()
if (lastDesktop <> desktop_Current) {
lastDesktop := desktop_Current
RegRead, themeID, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme
if ErrorLevel {
themeID = 0 ; Default to dark
}
Menu, Tray, Icon, %A_ScriptDir%\res\%themeID%\%desktop_Current%.ico
; OutputDebug, [DESKTOP] OnTheFly: %mode_OnTheFly%
}
Return
}
; Update Virtual Desktops from Registry
desktop_Update() {
; Get the UUID of Current Desktop
IdLength = 32
RegRead, desktop_CurrentId, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, CurrentVirtualDesktop
if ErrorLevel {
OutputDebug, [DESKTOP] CurrentVirtualDesktop Failed
Return
}
if (desktop_CurrentId) {
IdLength := StrLen(desktop_CurrentId)
}
RegRead, DesktopList, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, VirtualDesktopIDs
if ErrorLevel {
OutputDebug, [DESKTOP] VirtualDesktopIDs Failed
Return
}
; Count Desktops
if DesktopList {
DesktopListLength := StrLen(DesktopList)
desktop_Count := Floor(DesktopListLength / IdLength)
}
else {
desktop_Count = 1
}
; Find the Current Desktop
while (desktop_CurrentId and A_Index <= desktop_Count) {
StartPos := ((A_Index-1) * IdLength) + 1
DesktopIter := SubStr(DesktopList, StartPos, IdLength)
if (DesktopIter = desktop_CurrentId) {
desktop_Current := A_Index
Break
}
}
}
; Cycle Desktops
desktop_SwitchByCycle() {
; Check Update before Switch
desktop_Update()
if (desktop_Current < desktop_Count)
{
Send ^#{Right}
desktop_Current++
}
else
{
While(desktop_Current>1)
{
Send ^#{Left}
desktop_Current--
}
}
; OutputDebug, [DESKTOP] Current: %desktop_Current%
}
; Swtich Desktops by Number
desktop_SwitchByNumber(desktop_Target)
{
desktop_Update()
; Check Invalid Numbers
if (desktop_Count < desktop_Target) {
desktop_Target := desktop_Count
}
; Swith to Target Desktop by Sending Keys
while (desktop_Current < desktop_Target) {
Send ^#{Right}
desktop_Current++
}
while (desktop_Current > desktop_Target) {
Send ^#{Left}
desktop_Current--
}
; OutputDebug, [DESKTOP] Current: %desktop_Current%
}
; Create & Switch to a New Virtual Desktop
desktop_Create()
{
Send, #^d
desktop_Count++
desktop_Current = %desktop_Count%
; OutputDebug, [DESKTOP] Created, Count: %desktop_Count%
}
; Delete the Current Virtual Desktop
desktop_Delete()
{
Send, #^{F4}
desktop_Count--
desktop_Current--
; OutputDebug, [DESKTOP] Deleted, Count: %desktop_Count%
}
; Enable Autorun
autorun_Enable() {
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, %app_Name%, %A_ScriptFullPath%
if autorun_Check() {
Return True
}
Return False
}
; Disable Autorun
autorun_Disable() {
RegDelete, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run, %app_Name%
if autorun_Check() {
Return False
}
Return True
}
; Check Autorun Status
autorun_Check() {
RegRead, testPath, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, %app_Name%
if (testPath = A_ScriptFullPath) {
Menu, Tray, Check, Autorun
Return True
}
Menu, Tray, UnCheck, Autorun
Return False
}