-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathxHotkeyNormalize.ahk
34 lines (28 loc) · 1.12 KB
/
xHotkeyNormalize.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
HotkeyNormalize(Hotkey, ByRef UseHook:="", ByRef HasTilde:="", Excp:=-1) {
if p := InStr(Hotkey, " & ") {
return HotkeyNormalize(RTrim(SubStr(Hotkey, 1, p)),,, -2) " & "
. HotkeyNormalize(LTrim(SubStr(Hotkey, p+3)),,, -2)
}
Hotkey := RegExReplace(Hotkey, "i)[ `t]up$", "", isKeyUp, 1)
if !p := RegExMatch(Hotkey, "^[~$*<>^!+#]*\K(\w+|.)$")
throw Exception("Invalid hotkey", Excp, Hotkey)
mods := SubStr(Hotkey, 1, p-1)
if UseHook := InStr(mods, "$") != 0
mods := StrReplace(mods, "$")
if HasTilde := InStr(mods, "~") != 0
mods := StrReplace(mods, "~")
static allMods := StrSplit("* <^ <! <+ <# >^ >! >+ ># ^ ! + #", " ")
sortedMods := ""
if mods
for _, aMod in allMods
if InStr(mods, aMod)
sortedMods .= aMod, mods := StrReplace(mods, aMod)
key := SubStr(Hotkey, p)
if key ~= "i)^(.$|vk|sc)"
key := StrLower(key)
else if n := GetKeyName(key)
key := n
else
throw Exception("Unknown key", Excp, key)
return sortedMods . key . (isKeyUp ? " up" : "")
}