-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathhotkeyManager.ahk
48 lines (43 loc) · 1.33 KB
/
hotkeyManager.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
/*
* this function is used when a hotkey combo is pressed. It directs the program to the appropriate function in the appropriate class
*/
JPGIncDesktopManagerCallback(desktopManager, functionName, keyCombo)
{
desktopManager[functionName](getDesktopNumberFromHotkey(keyCombo))
return
}
class JPGIncHotkeyManager
{
_notAnAutohotkeyModKeyRegex := "[^#!^+<>*~$]"
__new()
{
return this
}
setupNumberedHotkey(callbackClass, callbackFunctionName, hotkeyKey)
{
if(this._doesHotkeyRequireCustomHotkeySyntax(hotkeyKey))
{
hotkeyKey .= " & "
}
Loop, 10
{
this.setupHotkey(callbackClass, callbackFunctionName, hotkeyKey (A_Index - 1))
}
return this
}
setupHotkey(callbackClass, callbackFunctionName, hotkeyKey)
{
;~ debugger("Setting up callback: " callbackFunctionName " as " hotkeyKey)
callback := Func("JPGIncDesktopManagerCallback").Bind(callbackClass, callbackFunctionName, hotkeyKey)
Hotkey, % hotkeyKey, % callback, On
return this
}
/*
* If the modifier key used is only a modifier symbol then we don't need to do anything (https://autohotkey.com/docs/Hotkeys.htm#Symbols)
* but if it contains any other characters then it means that the hotkey is a combination hotkey then we need to add " & "
*/
_doesHotkeyRequireCustomHotkeySyntax(key)
{
return RegExMatch(key, this._notAnAutohotkeyModKeyRegex)
}
}