-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathclass_CHotKey.ahk
116 lines (104 loc) · 2.28 KB
/
class_CHotKey.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
class CHotKey
{
hk := ""
label := ""
enabled := false
up := true
_hkString := ""
boundControls := {}
__New(hk, label, up=true)
{
this.hk := hk
this.label := label
this.up := true
this.enabled := false
this._hkString := this._ToString()
if(!this.Create())
ErrorLevel = 1
}
_GetInternalName()
{
hk := this.hk
if(this.up)
hk .= " Up"
return hk
}
Create()
{
Hotkey, % this._GetInternalName(), % this.label, off UseErrorLevel
; OutputDebug % "created hk " this.hk ", " ErrorLevel
if ErrorLevel
return false
else
return true
}
Enable()
{
Hotkey, % this._GetInternalName(), on, UseErrorLevel
; OutputDebug % "enabled hk " this.hk ", " ErrorLevel
if ErrorLevel
return false
else
{
this.enabled := true
return true
}
}
Disable()
{
; OutputDebug % "CHotKey.Disable()`n`tHK = " this.hk
; OutputDebug % "`tInternal name = " this._GetInternalName()
Hotkey, % this._GetInternalName(), off, UseErrorLevel
; OutputDebug `tErrorLevel = %ErrorLevel%
if ErrorLevel
return false
else
{
this.enabled := false
return true
}
}
;
; Function: ToString
; Description:
; Gets the hotkey display text as shown in a Hotkey GUI control.
; Syntax: CHotKey.ToString()
; Return Value:
; The display text of the hotkey.
;
ToString()
{
return this._hkString
}
;
; Function: _ToString
; Description:
; Transforms AutoHotkey hotkeys that can be obtained from Hotkey GUI control into the format displayed in the said control.
; Syntax: CHotKey._ToString()
; Return Value:
; The display text of the hotkey.
; Remarks:
; This method is for internal use (use ToString instead).
;
_ToString()
{
kstring := ""
if(InStr(this.hk, "^"))
kstring .= "Ctrl + "
if(InStr(this.hk, "+"))
kstring .= "Shift + "
if(InStr(this.hk, "!"))
kstring .= "Alt + "
hk := this.hk
StringReplace, hk, hk, ^
StringReplace, hk, hk, +
StringReplace, hk, hk, !
StringReplace, hk, hk, Numpad, Num%A_Space%
StringReplace, hk, hk, Add, +
StringReplace, hk, hk, Sub, -
StringReplace, hk, hk, Mult, *
StringReplace, hk, hk, Div, /
kstring .= hk
return kstring
}
}