-
Notifications
You must be signed in to change notification settings - Fork 890
/
keyboard.go
442 lines (419 loc) · 13.8 KB
/
keyboard.go
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
// Copyright 2013 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package walk
import (
"bytes"
)
import (
"github.com/lxn/win"
)
type Key uint16
func (k Key) String() string {
return key2string[k]
}
const (
KeyLButton Key = win.VK_LBUTTON
KeyRButton Key = win.VK_RBUTTON
KeyCancel Key = win.VK_CANCEL
KeyMButton Key = win.VK_MBUTTON
KeyXButton1 Key = win.VK_XBUTTON1
KeyXButton2 Key = win.VK_XBUTTON2
KeyBack Key = win.VK_BACK
KeyTab Key = win.VK_TAB
KeyClear Key = win.VK_CLEAR
KeyReturn Key = win.VK_RETURN
KeyShift Key = win.VK_SHIFT
KeyControl Key = win.VK_CONTROL
KeyAlt Key = win.VK_MENU
KeyMenu Key = win.VK_MENU
KeyPause Key = win.VK_PAUSE
KeyCapital Key = win.VK_CAPITAL
KeyKana Key = win.VK_KANA
KeyHangul Key = win.VK_HANGUL
KeyJunja Key = win.VK_JUNJA
KeyFinal Key = win.VK_FINAL
KeyHanja Key = win.VK_HANJA
KeyKanji Key = win.VK_KANJI
KeyEscape Key = win.VK_ESCAPE
KeyConvert Key = win.VK_CONVERT
KeyNonconvert Key = win.VK_NONCONVERT
KeyAccept Key = win.VK_ACCEPT
KeyModeChange Key = win.VK_MODECHANGE
KeySpace Key = win.VK_SPACE
KeyPrior Key = win.VK_PRIOR
KeyNext Key = win.VK_NEXT
KeyEnd Key = win.VK_END
KeyHome Key = win.VK_HOME
KeyLeft Key = win.VK_LEFT
KeyUp Key = win.VK_UP
KeyRight Key = win.VK_RIGHT
KeyDown Key = win.VK_DOWN
KeySelect Key = win.VK_SELECT
KeyPrint Key = win.VK_PRINT
KeyExecute Key = win.VK_EXECUTE
KeySnapshot Key = win.VK_SNAPSHOT
KeyInsert Key = win.VK_INSERT
KeyDelete Key = win.VK_DELETE
KeyHelp Key = win.VK_HELP
Key0 Key = 0x30
Key1 Key = 0x31
Key2 Key = 0x32
Key3 Key = 0x33
Key4 Key = 0x34
Key5 Key = 0x35
Key6 Key = 0x36
Key7 Key = 0x37
Key8 Key = 0x38
Key9 Key = 0x39
KeyA Key = 0x41
KeyB Key = 0x42
KeyC Key = 0x43
KeyD Key = 0x44
KeyE Key = 0x45
KeyF Key = 0x46
KeyG Key = 0x47
KeyH Key = 0x48
KeyI Key = 0x49
KeyJ Key = 0x4A
KeyK Key = 0x4B
KeyL Key = 0x4C
KeyM Key = 0x4D
KeyN Key = 0x4E
KeyO Key = 0x4F
KeyP Key = 0x50
KeyQ Key = 0x51
KeyR Key = 0x52
KeyS Key = 0x53
KeyT Key = 0x54
KeyU Key = 0x55
KeyV Key = 0x56
KeyW Key = 0x57
KeyX Key = 0x58
KeyY Key = 0x59
KeyZ Key = 0x5A
KeyLWin Key = win.VK_LWIN
KeyRWin Key = win.VK_RWIN
KeyApps Key = win.VK_APPS
KeySleep Key = win.VK_SLEEP
KeyNumpad0 Key = win.VK_NUMPAD0
KeyNumpad1 Key = win.VK_NUMPAD1
KeyNumpad2 Key = win.VK_NUMPAD2
KeyNumpad3 Key = win.VK_NUMPAD3
KeyNumpad4 Key = win.VK_NUMPAD4
KeyNumpad5 Key = win.VK_NUMPAD5
KeyNumpad6 Key = win.VK_NUMPAD6
KeyNumpad7 Key = win.VK_NUMPAD7
KeyNumpad8 Key = win.VK_NUMPAD8
KeyNumpad9 Key = win.VK_NUMPAD9
KeyMultiply Key = win.VK_MULTIPLY
KeyAdd Key = win.VK_ADD
KeySeparator Key = win.VK_SEPARATOR
KeySubtract Key = win.VK_SUBTRACT
KeyDecimal Key = win.VK_DECIMAL
KeyDivide Key = win.VK_DIVIDE
KeyF1 Key = win.VK_F1
KeyF2 Key = win.VK_F2
KeyF3 Key = win.VK_F3
KeyF4 Key = win.VK_F4
KeyF5 Key = win.VK_F5
KeyF6 Key = win.VK_F6
KeyF7 Key = win.VK_F7
KeyF8 Key = win.VK_F8
KeyF9 Key = win.VK_F9
KeyF10 Key = win.VK_F10
KeyF11 Key = win.VK_F11
KeyF12 Key = win.VK_F12
KeyF13 Key = win.VK_F13
KeyF14 Key = win.VK_F14
KeyF15 Key = win.VK_F15
KeyF16 Key = win.VK_F16
KeyF17 Key = win.VK_F17
KeyF18 Key = win.VK_F18
KeyF19 Key = win.VK_F19
KeyF20 Key = win.VK_F20
KeyF21 Key = win.VK_F21
KeyF22 Key = win.VK_F22
KeyF23 Key = win.VK_F23
KeyF24 Key = win.VK_F24
KeyNumlock Key = win.VK_NUMLOCK
KeyScroll Key = win.VK_SCROLL
KeyLShift Key = win.VK_LSHIFT
KeyRShift Key = win.VK_RSHIFT
KeyLControl Key = win.VK_LCONTROL
KeyRControl Key = win.VK_RCONTROL
KeyLAlt Key = win.VK_LMENU
KeyLMenu Key = win.VK_LMENU
KeyRAlt Key = win.VK_RMENU
KeyRMenu Key = win.VK_RMENU
KeyBrowserBack Key = win.VK_BROWSER_BACK
KeyBrowserForward Key = win.VK_BROWSER_FORWARD
KeyBrowserRefresh Key = win.VK_BROWSER_REFRESH
KeyBrowserStop Key = win.VK_BROWSER_STOP
KeyBrowserSearch Key = win.VK_BROWSER_SEARCH
KeyBrowserFavorites Key = win.VK_BROWSER_FAVORITES
KeyBrowserHome Key = win.VK_BROWSER_HOME
KeyVolumeMute Key = win.VK_VOLUME_MUTE
KeyVolumeDown Key = win.VK_VOLUME_DOWN
KeyVolumeUp Key = win.VK_VOLUME_UP
KeyMediaNextTrack Key = win.VK_MEDIA_NEXT_TRACK
KeyMediaPrevTrack Key = win.VK_MEDIA_PREV_TRACK
KeyMediaStop Key = win.VK_MEDIA_STOP
KeyMediaPlayPause Key = win.VK_MEDIA_PLAY_PAUSE
KeyLaunchMail Key = win.VK_LAUNCH_MAIL
KeyLaunchMediaSelect Key = win.VK_LAUNCH_MEDIA_SELECT
KeyLaunchApp1 Key = win.VK_LAUNCH_APP1
KeyLaunchApp2 Key = win.VK_LAUNCH_APP2
KeyOEM1 Key = win.VK_OEM_1
KeyOEMPlus Key = win.VK_OEM_PLUS
KeyOEMComma Key = win.VK_OEM_COMMA
KeyOEMMinus Key = win.VK_OEM_MINUS
KeyOEMPeriod Key = win.VK_OEM_PERIOD
KeyOEM2 Key = win.VK_OEM_2
KeyOEM3 Key = win.VK_OEM_3
KeyOEM4 Key = win.VK_OEM_4
KeyOEM5 Key = win.VK_OEM_5
KeyOEM6 Key = win.VK_OEM_6
KeyOEM7 Key = win.VK_OEM_7
KeyOEM8 Key = win.VK_OEM_8
KeyOEM102 Key = win.VK_OEM_102
KeyProcessKey Key = win.VK_PROCESSKEY
KeyPacket Key = win.VK_PACKET
KeyAttn Key = win.VK_ATTN
KeyCRSel Key = win.VK_CRSEL
KeyEXSel Key = win.VK_EXSEL
KeyErEOF Key = win.VK_EREOF
KeyPlay Key = win.VK_PLAY
KeyZoom Key = win.VK_ZOOM
KeyNoName Key = win.VK_NONAME
KeyPA1 Key = win.VK_PA1
KeyOEMClear Key = win.VK_OEM_CLEAR
)
var key2string = map[Key]string{
KeyLButton: "LButton",
KeyRButton: "RButton",
KeyCancel: "Cancel",
KeyMButton: "MButton",
KeyXButton1: "XButton1",
KeyXButton2: "XButton2",
KeyBack: "Back",
KeyTab: "Tab",
KeyClear: "Clear",
KeyReturn: "Return",
KeyShift: "Shift",
KeyControl: "Control",
KeyAlt: "Alt / Menu",
KeyPause: "Pause",
KeyCapital: "Capital",
KeyKana: "Kana / Hangul",
KeyJunja: "Junja",
KeyFinal: "Final",
KeyHanja: "Hanja / Kanji",
KeyEscape: "Escape",
KeyConvert: "Convert",
KeyNonconvert: "Nonconvert",
KeyAccept: "Accept",
KeyModeChange: "ModeChange",
KeySpace: "Space",
KeyPrior: "Prior",
KeyNext: "Next",
KeyEnd: "End",
KeyHome: "Home",
KeyLeft: "Left",
KeyUp: "Up",
KeyRight: "Right",
KeyDown: "Down",
KeySelect: "Select",
KeyPrint: "Print",
KeyExecute: "Execute",
KeySnapshot: "Snapshot",
KeyInsert: "Insert",
KeyDelete: "Delete",
KeyHelp: "Help",
Key0: "0",
Key1: "1",
Key2: "2",
Key3: "3",
Key4: "4",
Key5: "5",
Key6: "6",
Key7: "7",
Key8: "8",
Key9: "9",
KeyA: "A",
KeyB: "B",
KeyC: "C",
KeyD: "D",
KeyE: "E",
KeyF: "F",
KeyG: "G",
KeyH: "H",
KeyI: "I",
KeyJ: "J",
KeyK: "K",
KeyL: "L",
KeyM: "M",
KeyN: "N",
KeyO: "O",
KeyP: "P",
KeyQ: "Q",
KeyR: "R",
KeyS: "S",
KeyT: "T",
KeyU: "U",
KeyV: "V",
KeyW: "W",
KeyX: "X",
KeyY: "Y",
KeyZ: "Z",
KeyLWin: "LWin",
KeyRWin: "RWin",
KeyApps: "Apps",
KeySleep: "Sleep",
KeyNumpad0: "Numpad0",
KeyNumpad1: "Numpad1",
KeyNumpad2: "Numpad2",
KeyNumpad3: "Numpad3",
KeyNumpad4: "Numpad4",
KeyNumpad5: "Numpad5",
KeyNumpad6: "Numpad6",
KeyNumpad7: "Numpad7",
KeyNumpad8: "Numpad8",
KeyNumpad9: "Numpad9",
KeyMultiply: "Multiply",
KeyAdd: "Add",
KeySeparator: "Separator",
KeySubtract: "Subtract",
KeyDecimal: "Decimal",
KeyDivide: "Divide",
KeyF1: "F1",
KeyF2: "F2",
KeyF3: "F3",
KeyF4: "F4",
KeyF5: "F5",
KeyF6: "F6",
KeyF7: "F7",
KeyF8: "F8",
KeyF9: "F9",
KeyF10: "F10",
KeyF11: "F11",
KeyF12: "F12",
KeyF13: "F13",
KeyF14: "F14",
KeyF15: "F15",
KeyF16: "F16",
KeyF17: "F17",
KeyF18: "F18",
KeyF19: "F19",
KeyF20: "F20",
KeyF21: "F21",
KeyF22: "F22",
KeyF23: "F23",
KeyF24: "F24",
KeyNumlock: "Numlock",
KeyScroll: "Scroll",
KeyLShift: "LShift",
KeyRShift: "RShift",
KeyLControl: "LControl",
KeyRControl: "RControl",
KeyLMenu: "LMenu",
KeyRMenu: "RMenu",
KeyBrowserBack: "BrowserBack",
KeyBrowserForward: "BrowserForward",
KeyBrowserRefresh: "BrowserRefresh",
KeyBrowserStop: "BrowserStop",
KeyBrowserSearch: "BrowserSearch",
KeyBrowserFavorites: "BrowserFavorites",
KeyBrowserHome: "BrowserHome",
KeyVolumeMute: "VolumeMute",
KeyVolumeDown: "VolumeDown",
KeyVolumeUp: "VolumeUp",
KeyMediaNextTrack: "MediaNextTrack",
KeyMediaPrevTrack: "MediaPrevTrack",
KeyMediaStop: "MediaStop",
KeyMediaPlayPause: "MediaPlayPause",
KeyLaunchMail: "LaunchMail",
KeyLaunchMediaSelect: "LaunchMediaSelect",
KeyLaunchApp1: "LaunchApp1",
KeyLaunchApp2: "LaunchApp2",
KeyOEM1: "OEM1",
KeyOEMPlus: "OEMPlus",
KeyOEMComma: "OEMComma",
KeyOEMMinus: "OEMMinus",
KeyOEMPeriod: "OEMPeriod",
KeyOEM2: "OEM2",
KeyOEM3: "OEM3",
KeyOEM4: "OEM4",
KeyOEM5: "OEM5",
KeyOEM6: "OEM6",
KeyOEM7: "OEM7",
KeyOEM8: "OEM8",
KeyOEM102: "OEM102",
KeyProcessKey: "ProcessKey",
KeyPacket: "Packet",
KeyAttn: "Attn",
KeyCRSel: "CRSel",
KeyEXSel: "EXSel",
KeyErEOF: "ErEOF",
KeyPlay: "Play",
KeyZoom: "Zoom",
KeyNoName: "NoName",
KeyPA1: "PA1",
KeyOEMClear: "OEMClear",
}
type Modifiers byte
func (m Modifiers) String() string {
return modifiers2string[m]
}
var modifiers2string = map[Modifiers]string{
ModShift: "Shift",
ModControl: "Ctrl",
ModControl | ModShift: "Ctrl+Shift",
ModAlt: "Alt",
ModAlt | ModShift: "Alt+Shift",
ModAlt | ModControl: "Alt+Ctrl",
ModAlt | ModControl | ModShift: "Alt+Ctrl+Shift",
}
const (
ModShift Modifiers = 1 << iota
ModControl
ModAlt
)
func ModifiersDown() Modifiers {
var m Modifiers
if ShiftDown() {
m |= ModShift
}
if ControlDown() {
m |= ModControl
}
if AltDown() {
m |= ModAlt
}
return m
}
type Shortcut struct {
Modifiers Modifiers
Key Key
}
func (s Shortcut) String() string {
m := s.Modifiers.String()
if m == "" {
return s.Key.String()
}
b := new(bytes.Buffer)
b.WriteString(m)
b.WriteRune('+')
b.WriteString(s.Key.String())
return b.String()
}
func AltDown() bool {
return win.GetKeyState(int32(KeyAlt))>>15 != 0
}
func ControlDown() bool {
return win.GetKeyState(int32(KeyControl))>>15 != 0
}
func ShiftDown() bool {
return win.GetKeyState(int32(KeyShift))>>15 != 0
}