|
@@ -0,0 +1,207 @@
|
|
1
|
+
|
|
2
|
+enum Key {
|
|
3
|
+ A, B, C, D, E, F, G, H, I, J, K, M, L, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
|
|
4
|
+ D0, D1, D2, D3, D4, D5, D6, D7, D8, D9,
|
|
5
|
+ Up, Down, Left, Right,
|
|
6
|
+ Space, Enter, Tab, Delete, Insert,
|
|
7
|
+ PageDown, PageUp, Home, End,
|
|
8
|
+ Escape, LeftShift, LeftCtrl,
|
|
9
|
+ F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
|
|
10
|
+ Add, Subtract,
|
|
11
|
+ OemTilde, OemMinus, OemPlus, OemOpenBrackets, OemCloseBrackets, Oem5, OemComma, OemPeriod, OemSemicolon, OemQuotes, OemQuestion
|
|
12
|
+}
|
|
13
|
+
|
|
14
|
+class HotkeyParames {
|
|
15
|
+ static Separator: string = '@';
|
|
16
|
+ private static _keyList: { [key: string]: Key } = {
|
|
17
|
+ "A": Key.A,
|
|
18
|
+ "B": Key.B,
|
|
19
|
+ "C": Key.C,
|
|
20
|
+ "D": Key.D,
|
|
21
|
+ "E": Key.E,
|
|
22
|
+ "F": Key.F,
|
|
23
|
+ "G": Key.G,
|
|
24
|
+ "H": Key.H,
|
|
25
|
+ "I": Key.I,
|
|
26
|
+ "J": Key.J,
|
|
27
|
+ "K": Key.K,
|
|
28
|
+ "M": Key.M,
|
|
29
|
+ "L": Key.L,
|
|
30
|
+ "N": Key.N,
|
|
31
|
+ "O": Key.O,
|
|
32
|
+ "P": Key.P,
|
|
33
|
+ "Q": Key.Q,
|
|
34
|
+ "R": Key.R,
|
|
35
|
+ "S": Key.S,
|
|
36
|
+ "T": Key.T,
|
|
37
|
+ "U": Key.U,
|
|
38
|
+ "V": Key.V,
|
|
39
|
+ "W": Key.W,
|
|
40
|
+ "X": Key.X,
|
|
41
|
+ "Y": Key.Y,
|
|
42
|
+ "Z": Key.Z,
|
|
43
|
+
|
|
44
|
+ "0": Key.D0,
|
|
45
|
+ "1": Key.D1,
|
|
46
|
+ "2": Key.D2,
|
|
47
|
+ "3": Key.D3,
|
|
48
|
+ "4": Key.D4,
|
|
49
|
+ "5": Key.D5,
|
|
50
|
+ "6": Key.D6,
|
|
51
|
+ "7": Key.D7,
|
|
52
|
+ "8": Key.D8,
|
|
53
|
+ "9": Key.D9,
|
|
54
|
+
|
|
55
|
+ "Up": Key.Up,
|
|
56
|
+ "Down": Key.Down,
|
|
57
|
+ "Left": Key.Left,
|
|
58
|
+ "Right": Key.Right,
|
|
59
|
+
|
|
60
|
+ "Space": Key.Space,
|
|
61
|
+ "Enter": Key.Enter,
|
|
62
|
+ "Tab": Key.Tab,
|
|
63
|
+ "Del": Key.Delete,
|
|
64
|
+ "Insert": Key.Insert,
|
|
65
|
+
|
|
66
|
+ "PgDn": Key.PageDown,
|
|
67
|
+ "PgUp": Key.PageUp,
|
|
68
|
+ "Home": Key.Home,
|
|
69
|
+ "End": Key.End,
|
|
70
|
+
|
|
71
|
+ "Esc": Key.Escape,
|
|
72
|
+ "Shift": Key.LeftShift,
|
|
73
|
+ "Ctrl": Key.LeftCtrl,
|
|
74
|
+
|
|
75
|
+ "F1": Key.F1,
|
|
76
|
+ "F2": Key.F2,
|
|
77
|
+ "F3": Key.F3,
|
|
78
|
+ "F4": Key.F4,
|
|
79
|
+ "F5": Key.F5,
|
|
80
|
+ "F6": Key.F6,
|
|
81
|
+ "F7": Key.F7,
|
|
82
|
+ "F8": Key.F8,
|
|
83
|
+ "F9": Key.F9,
|
|
84
|
+ "F10": Key.F10,
|
|
85
|
+ "F11": Key.F11,
|
|
86
|
+ "F12": Key.F12,
|
|
87
|
+
|
|
88
|
+ "加号": Key.Add,
|
|
89
|
+ "减号": Key.Subtract,
|
|
90
|
+ "`": Key.OemTilde,
|
|
91
|
+ "-": Key.OemMinus,
|
|
92
|
+ "=": Key.OemPlus,
|
|
93
|
+ "[": Key.OemOpenBrackets,
|
|
94
|
+ "]": Key.OemCloseBrackets,
|
|
95
|
+ "\\": Key.Oem5,
|
|
96
|
+ ",": Key.OemComma,
|
|
97
|
+ ".": Key.OemPeriod,
|
|
98
|
+ ";": Key.OemSemicolon,
|
|
99
|
+ "'": Key.OemQuotes,
|
|
100
|
+ "/": Key.OemQuestion
|
|
101
|
+ };
|
|
102
|
+
|
|
103
|
+ private static _enableSelfKey: string[] = [
|
|
104
|
+ "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
|
|
105
|
+ "Tab", "Enter", "Esc", "Up", "Down", "Left", "Right", "PgUp", "PgDn", "Home", "End",
|
|
106
|
+ "Del", "Insert", "减号", "加号"
|
|
107
|
+ ];
|
|
108
|
+
|
|
109
|
+ static ParseKeyValue_FromIntToStr(keyValue: string): string {
|
|
110
|
+ keyValue = keyValue.replace("amp;", "");
|
|
111
|
+ let result = "";
|
|
112
|
+ if (keyValue === "") return result;
|
|
113
|
+ const parts = keyValue.split(HotkeyParames.Separator);
|
|
114
|
+ for (const item1 of parts) {
|
|
115
|
+ if (item1.trim().length <= 0) continue;
|
|
116
|
+ const subParts = item1.split('+');
|
|
117
|
+ for (const item2 of subParts) {
|
|
118
|
+ if (item2.trim().length <= 0) break;
|
|
119
|
+ result += HotkeyParames.GetNameByValue(Key[parseInt(item2)]) + " + ";
|
|
120
|
+ }
|
|
121
|
+ result = result.trim().substring(0, result.trim().length - 1).trim() + HotkeyParames.Separator;
|
|
122
|
+ }
|
|
123
|
+ return result;
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ static ParseKeyValue_FromStrToInt(keyValue: string): string {
|
|
127
|
+ let result = "";
|
|
128
|
+ if (keyValue === "") return "0;";
|
|
129
|
+ const parts = keyValue.split(HotkeyParames.Separator);
|
|
130
|
+ for (const item1 of parts) {
|
|
131
|
+ if (item1.trim().length <= 0) continue;
|
|
132
|
+ const subParts = item1.split('+');
|
|
133
|
+ for (const item of subParts) {
|
|
134
|
+ if (item.trim().length <= 0) break;
|
|
135
|
+ result += HotkeyParames.GetValueByName(item.trim()) + "+";
|
|
136
|
+ }
|
|
137
|
+ result = result.substring(0, result.length - 1) + HotkeyParames.Separator;
|
|
138
|
+ }
|
|
139
|
+ return result;
|
|
140
|
+ }
|
|
141
|
+
|
|
142
|
+ static GetNameByValue(keyValue: Key): string {
|
|
143
|
+ keyValue = HotkeyParames.UniKey(keyValue);
|
|
144
|
+ const keyName = Object.keys(HotkeyParames._keyList).find(key => HotkeyParames._keyList[key] === keyValue);
|
|
145
|
+ return keyName || "";
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+ static GetValueByName(keyName: string): Key {
|
|
149
|
+ if (keyName === "") return Key.None;
|
|
150
|
+ return HotkeyParames._keyList[keyName] || Key.None;
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ static UniKey(keyValue: Key): Key {
|
|
154
|
+ switch (keyValue) {
|
|
155
|
+ case Key.RightCtrl:
|
|
156
|
+ return Key.LeftCtrl;
|
|
157
|
+ case Key.RightShift:
|
|
158
|
+ return Key.LeftShift;
|
|
159
|
+ case Key.Return:
|
|
160
|
+ return Key.Enter;
|
|
161
|
+ case Key.NumPad0:
|
|
162
|
+ return Key.D0;
|
|
163
|
+ case Key.NumPad1:
|
|
164
|
+ return Key.D1;
|
|
165
|
+ case Key.NumPad2:
|
|
166
|
+ return Key.D2;
|
|
167
|
+ case Key.NumPad3:
|
|
168
|
+ return Key.D3;
|
|
169
|
+ case Key.NumPad4:
|
|
170
|
+ return Key.D4;
|
|
171
|
+ case Key.NumPad5:
|
|
172
|
+ return Key.D5;
|
|
173
|
+ case Key.NumPad6:
|
|
174
|
+ return Key.D6;
|
|
175
|
+ case Key.NumPad7:
|
|
176
|
+ return Key.D7;
|
|
177
|
+ case Key.NumPad8:
|
|
178
|
+ return Key.D8;
|
|
179
|
+ case Key.NumPad9:
|
|
180
|
+ return Key.D9;
|
|
181
|
+ default:
|
|
182
|
+ return keyValue;
|
|
183
|
+ }
|
|
184
|
+ }
|
|
185
|
+
|
|
186
|
+ static CombHotKey(cont: string): string {
|
|
187
|
+ if (cont === "") return "";
|
|
188
|
+ let result: string;
|
|
189
|
+
|
|
190
|
+ if (cont === "Shift" || cont === "Ctrl") cont = "";
|
|
191
|
+
|
|
192
|
+ const modifiers = "";
|
|
193
|
+ if (modifiers.toLowerCase().includes("alt")) return "";
|
|
194
|
+ if (modifiers.toLowerCase() !== "none") {
|
|
195
|
+ result = modifiers.replace(',', '+') + "+" + cont;
|
|
196
|
+ } else if (HotkeyParames._enableSelfKey.includes(cont)) {
|
|
197
|
+ result = cont;
|
|
198
|
+ } else {
|
|
199
|
+ result = "Ctrl + " + cont;
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ result = result.replace("Control", "Ctrl").replace(" ", "").replace("+", " + ");
|
|
203
|
+ return result;
|
|
204
|
+ }
|
|
205
|
+}
|
|
206
|
+
|
|
207
|
+export default HotkeyParames;
|