-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinternal_key.go
112 lines (95 loc) · 2.55 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
)
func (k keyKind) device() DeviceKind {
switch k {
case keyKeyboard, keyKeyboardWithCtrl, keyKeyboardWithShift, keyKeyboardWithCtrlShift:
return KeyboardDevice
case keyGamepad, keyGamepadLeftStick, keyGamepadRightStick, keyGamepadStickMotion:
return GamepadDevice
case keyMouse, keyMouseDrag:
return MouseDevice
case keyWheel, keyWheelWithCtrl, keyWheelWithShift, keyWheelWithCtrlShift:
return MouseDevice
case keyMouseWithCtrl, keyMouseWithShift, keyMouseWithCtrlShift:
return MouseDevice | KeyboardDevice
case keyTouch, keyTouchDrag:
return TouchDevice
default:
return KeyboardDevice
}
}
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,
}