-
Notifications
You must be signed in to change notification settings - Fork 10
/
input.go
480 lines (450 loc) · 9.63 KB
/
input.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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
package pixel
type Action int
// String returns a human-readable string describing the Button.
func (a Action) String() string {
name, ok := actionNames[a]
if !ok {
return actionNames[UnknownAction]
}
return name
}
const UnknownAction Action = -1
const (
Release Action = iota
Press
Repeat
)
var actionNames = map[Action]string{
Release: "Release",
Press: "Press",
Repeat: "Repeat",
UnknownAction: "UnknownAction",
}
type Button int
// String returns a human-readable string describing the Button.
func (b Button) String() string {
name, ok := buttonNames[b]
if !ok {
return buttonNames[UnknownButton]
}
return name
}
// IsMouseButton returns true if the button is one of the mouse buttons.
func (b Button) IsMouseButton() bool {
return b >= mouseButtonStart && b <= mouseButtonEnd
}
// IsKeyboardButton returns true if the button is one of the keyboard buttons.
func (b Button) IsKeyboardButton() bool {
return b >= keyButtonStart && b <= keyButtonEnd
}
const UnknownButton Button = -1
const (
// List of all mouse buttons.
MouseButton1 Button = iota
MouseButton2
MouseButton3
MouseButton4
MouseButton5
MouseButton6
MouseButton7
MouseButton8
// List of all keyboard buttons.
KeySpace
KeyApostrophe
KeyComma
KeyMinus
KeyPeriod
KeySlash
Key0
Key1
Key2
Key3
Key4
Key5
Key6
Key7
Key8
Key9
KeySemicolon
KeyEqual
KeyA
KeyB
KeyC
KeyD
KeyE
KeyF
KeyG
KeyH
KeyI
KeyJ
KeyK
KeyL
KeyM
KeyN
KeyO
KeyP
KeyQ
KeyR
KeyS
KeyT
KeyU
KeyV
KeyW
KeyX
KeyY
KeyZ
KeyLeftBracket
KeyBackslash
KeyRightBracket
KeyGraveAccent
KeyWorld1
KeyWorld2
KeyEscape
KeyEnter
KeyTab
KeyBackspace
KeyInsert
KeyDelete
KeyRight
KeyLeft
KeyDown
KeyUp
KeyPageUp
KeyPageDown
KeyHome
KeyEnd
KeyCapsLock
KeyScrollLock
KeyNumLock
KeyPrintScreen
KeyPause
KeyF1
KeyF2
KeyF3
KeyF4
KeyF5
KeyF6
KeyF7
KeyF8
KeyF9
KeyF10
KeyF11
KeyF12
KeyF13
KeyF14
KeyF15
KeyF16
KeyF17
KeyF18
KeyF19
KeyF20
KeyF21
KeyF22
KeyF23
KeyF24
KeyF25
KeyKP0
KeyKP1
KeyKP2
KeyKP3
KeyKP4
KeyKP5
KeyKP6
KeyKP7
KeyKP8
KeyKP9
KeyKPDecimal
KeyKPDivide
KeyKPMultiply
KeyKPSubtract
KeyKPAdd
KeyKPEnter
KeyKPEqual
KeyLeftShift
KeyLeftControl
KeyLeftAlt
KeyLeftSuper
KeyRightShift
KeyRightControl
KeyRightAlt
KeyRightSuper
KeyMenu
// Last iota
NumButtons int = iota
// Internal mappings bookending keyboard and mouse buttons.
mouseButtonStart = MouseButton1
mouseButtonEnd = MouseButton8
keyButtonStart = KeySpace
keyButtonEnd = KeyMenu
// Aliases
MouseButtonLeft = MouseButton1
MouseButtonRight = MouseButton2
MouseButtonMiddle = MouseButton3
)
var buttonNames = map[Button]string{
MouseButton4: "MouseButton4",
MouseButton5: "MouseButton5",
MouseButton6: "MouseButton6",
MouseButton7: "MouseButton7",
MouseButton8: "MouseButton8",
MouseButtonLeft: "MouseButtonLeft",
MouseButtonRight: "MouseButtonRight",
MouseButtonMiddle: "MouseButtonMiddle",
KeySpace: "Space",
KeyApostrophe: "Apostrophe",
KeyComma: "Comma",
KeyMinus: "Minus",
KeyPeriod: "Period",
KeySlash: "Slash",
Key0: "0",
Key1: "1",
Key2: "2",
Key3: "3",
Key4: "4",
Key5: "5",
Key6: "6",
Key7: "7",
Key8: "8",
Key9: "9",
KeySemicolon: "Semicolon",
KeyEqual: "Equal",
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",
KeyLeftBracket: "LeftBracket",
KeyBackslash: "Backslash",
KeyRightBracket: "RightBracket",
KeyGraveAccent: "GraveAccent",
KeyWorld1: "World1",
KeyWorld2: "World2",
KeyEscape: "Escape",
KeyEnter: "Enter",
KeyTab: "Tab",
KeyBackspace: "Backspace",
KeyInsert: "Insert",
KeyDelete: "Delete",
KeyRight: "Right",
KeyLeft: "Left",
KeyDown: "Down",
KeyUp: "Up",
KeyPageUp: "PageUp",
KeyPageDown: "PageDown",
KeyHome: "Home",
KeyEnd: "End",
KeyCapsLock: "CapsLock",
KeyScrollLock: "ScrollLock",
KeyNumLock: "NumLock",
KeyPrintScreen: "PrintScreen",
KeyPause: "Pause",
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",
KeyF25: "F25",
KeyKP0: "KP0",
KeyKP1: "KP1",
KeyKP2: "KP2",
KeyKP3: "KP3",
KeyKP4: "KP4",
KeyKP5: "KP5",
KeyKP6: "KP6",
KeyKP7: "KP7",
KeyKP8: "KP8",
KeyKP9: "KP9",
KeyKPDecimal: "KPDecimal",
KeyKPDivide: "KPDivide",
KeyKPMultiply: "KPMultiply",
KeyKPSubtract: "KPSubtract",
KeyKPAdd: "KPAdd",
KeyKPEnter: "KPEnter",
KeyKPEqual: "KPEqual",
KeyLeftShift: "LeftShift",
KeyLeftControl: "LeftControl",
KeyLeftAlt: "LeftAlt",
KeyLeftSuper: "LeftSuper",
KeyRightShift: "RightShift",
KeyRightControl: "RightControl",
KeyRightAlt: "RightAlt",
KeyRightSuper: "RightSuper",
KeyMenu: "Menu",
UnknownButton: "UnknownButton",
}
// Joystick is a joystick or controller (gamepad).
type Joystick int
// String returns a human-readable string describing the Joystick.
func (j Joystick) String() string {
name, ok := joystickNames[j]
if !ok {
return joystickNames[UnknownJoystick]
}
return name
}
// List all of the joysticks.
const UnknownJoystick Joystick = -1
const (
Joystick1 Joystick = iota
Joystick2
Joystick3
Joystick4
Joystick5
Joystick6
Joystick7
Joystick8
Joystick9
Joystick10
Joystick11
Joystick12
Joystick13
Joystick14
Joystick15
Joystick16
// Last iota
NumJoysticks int = iota
)
var joystickNames = map[Joystick]string{
Joystick1: "Joystick1",
Joystick2: "Joystick2",
Joystick3: "Joystick3",
Joystick4: "Joystick4",
Joystick5: "Joystick5",
Joystick6: "Joystick6",
Joystick7: "Joystick7",
Joystick8: "Joystick8",
Joystick9: "Joystick9",
Joystick10: "Joystick10",
Joystick11: "Joystick11",
Joystick12: "Joystick12",
Joystick13: "Joystick13",
Joystick14: "Joystick14",
Joystick15: "Joystick15",
Joystick16: "Joystick16",
UnknownJoystick: "UnknownJoystick",
}
// GamepadAxis corresponds to a gamepad axis.
type GamepadAxis int
// String returns a human-readable string describing the GamepadAxis.
func (ga GamepadAxis) String() string {
name, ok := gamepadAxisNames[ga]
if !ok {
return gamepadAxisNames[UnknownGamepadAxis]
}
return name
}
// Gamepad axis IDs.
const UnknownGamepadAxis GamepadAxis = -1
const (
AxisLeftX GamepadAxis = iota
AxisLeftY
AxisRightX
AxisRightY
AxisLeftTrigger
AxisRightTrigger
// Last iota.
NumAxes int = iota
)
var gamepadAxisNames = map[GamepadAxis]string{
AxisLeftX: "AxisLeftX",
AxisLeftY: "AxisLeftY",
AxisRightX: "AxisRightX",
AxisRightY: "AxisRightY",
AxisLeftTrigger: "AxisLeftTrigger",
AxisRightTrigger: "AxisRightTrigger",
UnknownGamepadAxis: "UnknownGamepadAxis",
}
// GamepadButton corresponds to a gamepad button.
type GamepadButton int
// String returns a human-readable string describing the GamepadButton.
func (gb GamepadButton) String() string {
name, ok := gamepadButtonNames[gb]
if !ok {
return gamepadButtonNames[UnknownGampadButton]
}
return name
}
// Gamepad button IDs.
const UnknownGampadButton GamepadButton = -1
const (
GamepadA GamepadButton = iota
GamepadB
GamepadX
GamepadY
GamepadLeftBumper
GamepadRightBumper
GamepadBack
GamepadStart
GamepadGuide
GamepadLeftThumb
GamepadRightThumb
GamepadDpadUp
GamepadDpadRight
GamepadDpadDown
GamepadDpadLeft
// Last iota
NumGamepadButtons int = iota
// Aliases
GamepadCross = GamepadA
GamepadCircle = GamepadB
GamepadSquare = GamepadX
GamepadTriangle = GamepadY
)
var gamepadButtonNames = map[GamepadButton]string{
GamepadA: "GamepadA",
GamepadB: "GamepadB",
GamepadX: "GamepadX",
GamepadY: "GamepadY",
GamepadLeftBumper: "GamepadLeftBumper",
GamepadRightBumper: "GamepadRightBumper",
GamepadBack: "GamepadBack",
GamepadStart: "GamepadStart",
GamepadGuide: "GamepadGuide",
GamepadLeftThumb: "GamepadLeftThumb",
GamepadRightThumb: "GamepadRightThumb",
GamepadDpadUp: "GamepadDpadUp",
GamepadDpadRight: "GamepadDpadRight",
GamepadDpadDown: "GamepadDpadDown",
GamepadDpadLeft: "GamepadDpadLeft",
UnknownGampadButton: "UnknownGampadButton",
}