-
Notifications
You must be signed in to change notification settings - Fork 0
/
reDHotKeys.ahk
497 lines (427 loc) · 12.2 KB
/
reDHotKeys.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
#Requires AutoHotkey v1.1.33+
#SingleInstance Force
#NoEnv
#KeyHistory 0
SetWorkingDir %A_ScriptDir%
SetCapsLockState, AlwaysOff
SendMode Input
DesktopCount := 2
CurrentDesktop := 1
LastOpenedDesktop := 1
hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", A_ScriptDir . "\VirtualDesktopAccessor.dll", "Ptr")
global IsWindowOnDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "IsWindowOnDesktopNumber", "Ptr")
global MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "MoveWindowToDesktopNumber", "Ptr")
global GoToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "GoToDesktopNumber", "Ptr")
SetKeyDelay, 75
mapDesktopsFromRegistry()
OutputDebug, [loading] desktops: %DesktopCount% current: %CurrentDesktop%
#Include %A_ScriptDir%\dragonFlames.ahk
return
; CapsLock Vim Toggle
vimToggleModeOnHold(){
KeyWait, CapsLock, T0.4
If !ErrorLevel
send, {Esc}
Else
If GetKeyState("CapsLock","p")
SetCapsLockState, Off
else
SetCapsLockState, On
return
}
$k::
If GetKeyState("CapsLock","p")
Send {Up}
else
Send k
Return
$h::
If GetKeyState("CapsLock","p")
Send {Left}
else
Send h
Return
$j::
If GetKeyState("CapsLock","p")
Send {Down}
else
Send j
Return
$l::
If GetKeyState("CapsLock","p")
Send {Right}
else
Send l
Return
$x::
If GetKeyState("CapsLock","p")
Send, {Delete}
else
Send x
Return
$z::
If GetKeyState("CapsLock","p")
Send, {BackSpace}
else
Send z
Return
$d::
If GetKeyState("CapsLock","p"){
Send, {End}
Send, {LShift Down}
Send, {Up}
Send, {End}
Send, {LShift Up}
Send, ^x
}
else
Send d
Return
$c::
If GetKeyState("CapsLock","p")
If (A_PriorHotkey <> "$c" or A_TimeSincePriorHotkey > 400)
{
KeyWait, c
Send, c
return
}
Else{
Send, {End}
Send, {LShift Down}
Send, {Home}
Send, {LShift Up}
Send, ^x
}
else
Send c
Return
$o::
If GetKeyState("CapsLock","p"){
KeyWait, o ; wait for z to be released
KeyWait, o, D T0.1 ; and pressed again within 0.2 seconds
If ErrorLevel ; timed-out (only a single press)
Send {End}{Enter}
Else
Send {Up}{End}{Enter}
}
else
Send o
Return
$u::
If GetKeyState("CapsLock","p")
Send ^z
else
Send u
Return
$r::
If GetKeyState("CapsLock","p")
Send ^+z
else
Send r
Return
$p::
If GetKeyState("CapsLock","p")
Send ^v
else
Send p
Return
$y::
If GetKeyState("CapsLock","p")
Send ^c
else
Send y
Return
$v::
If GetKeyState("CapsLock","p"){
If GetKeyState("LShift","Down"){
Send, {LShift Up}
}
else
Send, {LShift Down}
}
else
Send v
Return
$e::
If GetKeyState("CapsLock","p")
Send ^{Right}
else
Send e
Return
$b::
If GetKeyState("CapsLock","p")
Send ^{Left}
else
Send b
Return
$f::
If GetKeyState("CapsLock","p")
Send {F12}
else
Send f
Return
$g::
If GetKeyState("CapsLock","p")
If (A_PriorHotkey <> "$g" or A_TimeSincePriorHotkey > 400)
{
KeyWait, g
Send, ^{End}
return
}
Else
Send, ^{Home}
else
Send g
Return
$0::
If GetKeyState("CapsLock","p")
Send {Home}
else
Send 0
Return
$6::
If GetKeyState("CapsLock","p")
Send {End}
else
Send, {6}
Return
; Windows Kep To FlowLauncher
winToFlowLauncher(){
If ProcessExist("Flow.Launcher.exe"){
KeyWait, LWin, T0.15
If !ErrorLevel
Send, !{Space}
Else
Send, {LWin Down}
KeyWait, LWin
}else{
Send, {LWin Down}
KeyWait, LWin
}
Send, {LWin Up}
}
; Redragon Volume Knob
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
for i in monitors {
curt := i.CurrentBrightness
break
}
if (curt < minBrightness)
curt := minBrightness
toSet := curt + step
if (toSet > 100)
return
if (toSet < minBrightness)
toSet := minBrightness
for i in monMethods {
i.WmiSetBrightness(1, toSet)
break
}
}
toggleScrollOrMouseY(step){
If GetKeyState("ScrollLock","t")
MouseMove, 0, %step%, 50, R
else
If step > 0
MouseClick,WheelUp,,,1,0,D,R
else
MouseClick,WheelDown,,,1,0,D,R
Return
}
toggleScrollOrMouseX(step){
If GetKeyState("ScrollLock","t")
MouseMove, %step%,0, 50, R
else
If step > 0
AdjustScreenBrightness(step)
else
AdjustScreenBrightness(step)
Return
}
mouseClick(){
Click
}
; Spaace Nagic Key For Virtual Windows
ProcessExist(Name){
Process,Exist,%Name%
return Errorlevel
}
showAllVirtualDesktop(){
Send, {LWin Down}
Send, {Tab Down}
Send, {Tab Up}
Send, {LWin Up}
}
mapDesktopsFromRegistry()
{
global CurrentDesktop, DesktopCount
IdLength := 32
SessionId := getSessionId()
if (SessionId) {
RegRead, CurrentDesktopId, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, CurrentVirtualDesktop
if ErrorLevel {
RegRead, CurrentDesktopId, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\%SessionId%\VirtualDesktops, CurrentVirtualDesktop
}
if (CurrentDesktopId) {
IdLength := StrLen(CurrentDesktopId)
}
}
RegRead, DesktopList, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, VirtualDesktopIDs
if (DesktopList) {
DesktopListLength := StrLen(DesktopList)
DesktopCount := floor(DesktopListLength / IdLength)
}
else {
DesktopCount := 1
}
i := 0
while (CurrentDesktopId and i < DesktopCount) {
StartPos := (i * IdLength) + 1
DesktopIter := SubStr(DesktopList, StartPos, IdLength)
OutputDebug, The iterator is pointing at %DesktopIter% and count is %i%.
if (DesktopIter = CurrentDesktopId) {
CurrentDesktop := i + 1
OutputDebug, Current desktop number is %CurrentDesktop% with an ID of %DesktopIter%.
break
}
i++
}
}
getSessionId()
{
ProcessId := DllCall("GetCurrentProcessId", "UInt")
if ErrorLevel {
OutputDebug, Error getting current process id: %ErrorLevel%
return
}
OutputDebug, Current Process Id: %ProcessId%
DllCall("ProcessIdToSessionId", "UInt", ProcessId, "UInt*", SessionId)
if ErrorLevel {
OutputDebug, Error getting session id: %ErrorLevel%
return
}
OutputDebug, Current Session Id: %SessionId%
return SessionId
}
_switchDesktopToTarget(targetDesktop)
{
global CurrentDesktop, DesktopCount, LastOpenedDesktop
if (targetDesktop > DesktopCount || targetDesktop < 1 || targetDesktop == CurrentDesktop) {
OutputDebug, [invalid] target: %targetDesktop% current: %CurrentDesktop%
return
}
LastOpenedDesktop := CurrentDesktop
WinActivate, ahk_class Shell_TrayWnd
DllCall(GoToDesktopNumberProc, Int, targetDesktop-1)
Sleep, 50
focusTheForemostWindow(targetDesktop)
}
updateGlobalVariables()
{
mapDesktopsFromRegistry()
}
switchDesktopByNumber(targetDesktop)
{
global CurrentDesktop, DesktopCount
updateGlobalVariables()
_switchDesktopToTarget(targetDesktop)
ToolTip, %targetDesktop%, 9999, 9999
SetTimer, RemoveToolTip, 2000
return
}
switchDesktopToLastOpened()
{
global CurrentDesktop, DesktopCount, LastOpenedDesktop
updateGlobalVariables()
_switchDesktopToTarget(LastOpenedDesktop)
}
switchDesktopToRight()
{
global CurrentDesktop, DesktopCount
updateGlobalVariables()
_switchDesktopToTarget(CurrentDesktop == DesktopCount ? 1 : CurrentDesktop + 1)
}
switchDesktopToLeft()
{
global CurrentDesktop, DesktopCount
updateGlobalVariables()
_switchDesktopToTarget(CurrentDesktop == 1 ? DesktopCount : CurrentDesktop - 1)
}
focusTheForemostWindow(targetDesktop) {
foremostWindowId := getForemostWindowIdOnDesktop(targetDesktop)
if isWindowNonMinimized(foremostWindowId) {
WinActivate, ahk_id %foremostWindowId%
}
}
isWindowNonMinimized(windowId) {
WinGet MMX, MinMax, ahk_id %windowId%
return MMX != -1
}
getForemostWindowIdOnDesktop(n)
{
n := n - 1
WinGet winIDList, list
Loop % winIDList {
windowID := % winIDList%A_Index%
windowIsOnDesktop := DllCall(IsWindowOnDesktopNumberProc, UInt, windowID, UInt, n)
if (windowIsOnDesktop == 1) {
return windowID
}
}
}
MoveCurrentWindowToDesktop(desktopNumber) {
WinGet, activeHwnd, ID, A
DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, desktopNumber - 1)
switchDesktopByNumber(desktopNumber)
ToolTip, %targetDesktop%, 9999, 9999
SetTimer, RemoveToolTip, 2000
return
}
MoveCurrentWindowToRightDesktop()
{
global CurrentDesktop, DesktopCount
updateGlobalVariables()
WinGet, activeHwnd, ID, A
DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, (CurrentDesktop == DesktopCount ? 1 : CurrentDesktop + 1) - 1)
_switchDesktopToTarget(CurrentDesktop == DesktopCount ? 1 : CurrentDesktop + 1)
}
MoveCurrentWindowToLeftDesktop()
{
global CurrentDesktop, DesktopCount
updateGlobalVariables()
WinGet, activeHwnd, ID, A
DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, (CurrentDesktop == 1 ? DesktopCount : CurrentDesktop - 1) - 1)
_switchDesktopToTarget(CurrentDesktop == 1 ? DesktopCount : CurrentDesktop - 1)
}
createVirtualDesktop()
{
global CurrentDesktop, DesktopCount
Send, #^d
DesktopCount++
CurrentDesktop := DesktopCount
OutputDebug, [create] desktops: %DesktopCount% current: %CurrentDesktop%
}
deleteVirtualDesktop()
{
global CurrentDesktop, DesktopCount, LastOpenedDesktop
Send, #^{F4}
if (LastOpenedDesktop >= CurrentDesktop) {
LastOpenedDesktop--
}
DesktopCount--
CurrentDesktop--
OutputDebug, [delete] desktops: %DesktopCount% current: %CurrentDesktop%
}
showHelpToolTip(){
ToolTip, Space Functions : `nSpace + ? : Show this help`nSpace + ` : Show all virtual Desktops`nSpace + Tab : Switch to last opened desktop`nSpace + 1-9 : Switch to virtual desktop 1-9`nSpace + J/K : Switch to left/right virtual desktop`nSpace + +/_ : Create or Delete Current Virtual Desktop`nSpace + Q-O : Move current window to virtual desktop 1-9`nSpace + H/L : Move current window to left/right virtual desktop`n`nCapsLock Functions : `nCapsLock + J/K/H/L : Move The Cursor Down/Up/Left/Right`nCapsLock + X : Delete`nCapsLock + Z : Backspace`nCapsLock + D : Delete the Entire Line`nCapsLock + C*2 : Delete the Entire Text in a Line`nCapsLock + O : Enter in a New Line`nCapsLock + O*2 : Enter in a New Line Above`nCapsLock + U/R : Undo/Redo`nCapsLock + Y/P : Copy/Paste`nCapsLock + V : Visual Mode`nCapsLock + E/B : Move the Cursor to End/Begining of a Word`nCapsLock + ^/0 : Move the Cursor to End/Begining of the Line`nCapsLock + G/G*2 : Move the Cursor to End/Begining of the File`nCapsLock + F : Go to the defination`n`nKnob Functions : `nCtrl + Knob + ↑/↓ : Scroll Up/Down`nAlt + Knob + ↑/↓ : Turn Brightness Up/Down`nCtrl + Knob + ↑/↓ (ScrollLockOn) : Move the Mouse Up/Down`nAlt + Knob + ↑/↓ (ScrollLockOn) : Move the Mouse Left/Right`nPause : Mouse Click`n`nOther Functions : `nLWin : Flowlauncer hotkey when FlowLauncher is active`nAlt + X : Close Current Window`nRAlt : Enter
SetTimer, RemoveToolTip, 2000
return
}
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return