-
Notifications
You must be signed in to change notification settings - Fork 8
/
internal_key.go
93 lines (77 loc) · 1.96 KB
/
internal_key.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
package input
type keyKind uint8
const (
keyKeyboard keyKind = iota
keyKeyboardWithCtrl
keyKeyboardWithShift
keyKeyboardWithCtrlShift
keyGamepad
keyGamepadLeftStick
keyGamepadRightStick
keyGamepadStickMotion
keyMouse
keyMouseWithCtrl
keyMouseWithShift
keyMouseWithCtrlShift
keyMouseDrag
keyTouch
keyTouchDrag
keyWheel
keyWheelWithCtrl
keyWheelWithShift
keyWheelWithCtrlShift
keySimulated
)
type touchCode int
const (
touchUnknown touchCode = iota
touchTap
touchLongTap
touchDrag
)
type wheelCode int
const (
wheelUnknown wheelCode = iota
wheelUp
wheelDown
wheelVertical
)
type stickCode int
const (
stickUnknown stickCode = iota
stickUp
stickRight
stickDown
stickLeft
)
type keyKindFlag uint8
const (
keyFlagHasPos keyKindFlag = 1 << iota
keyFlagNeedID
keyFlagHasDuration
)
func keyHasPos(k keyKind) bool { return keyKindFlagTable[k]&keyFlagHasPos != 0 }
func keyNeedID(k keyKind) bool { return keyKindFlagTable[k]&keyFlagNeedID != 0 }
func keyHasDuration(k keyKind) bool { return keyKindFlagTable[k]&keyFlagHasDuration != 0 }
// Using a 256-byte LUT to get a fast map-like lookup without a bound check.
var keyKindFlagTable = [256]keyKindFlag{
keySimulated: keyFlagHasPos | keyFlagNeedID,
keyKeyboard: keyFlagHasDuration,
keyKeyboardWithCtrl: keyFlagHasDuration,
keyKeyboardWithShift: keyFlagHasDuration,
keyKeyboardWithCtrlShift: keyFlagHasDuration,
keyGamepad: keyFlagNeedID,
keyGamepadLeftStick: keyFlagNeedID,
keyGamepadRightStick: keyFlagNeedID,
keyGamepadStickMotion: keyFlagHasPos | keyFlagNeedID,
keyMouse: keyFlagHasPos,
keyMouseWithCtrl: keyFlagHasPos,
keyMouseWithShift: keyFlagHasPos,
keyMouseWithCtrlShift: keyFlagHasPos,
keyMouseDrag: keyFlagHasPos,
keyTouch: keyFlagHasPos,
keyWheel: keyFlagHasPos,
keyWheelWithCtrl: keyFlagHasPos,
keyWheelWithShift: keyFlagHasPos,
keyWheelWithCtrlShift: keyFlagHasPos,
}