keys: Refactoring: Rename and reverse a map (androidKeyToDriverKeyName)

This commit is contained in:
Hajime Hoshi 2020-02-22 02:46:09 +09:00
parent 6d78610645
commit cd4cb435f2
2 changed files with 127 additions and 127 deletions

View File

@ -34,10 +34,10 @@ import (
)
var (
nameToGLFWKey map[string]glfw.Key
nameToAndroidKey map[string]int
nameToJSKey map[string]string
edgeKeyCodeToName map[int]string
nameToGLFWKey map[string]glfw.Key
androidKeyToDriverKeyName map[int]string
nameToJSKey map[string]string // TODO: Rename this
edgeKeyCodeToName map[int]string
)
func init() {
@ -96,52 +96,52 @@ func init() {
}
// https://developer.android.com/reference/android/view/KeyEvent
nameToAndroidKey = map[string]int{
"Comma": 55,
"Period": 56,
"LeftAlt": 57,
"RightAlt": 58,
"CapsLock": 115,
"LeftControl": 113,
"RightControl": 114,
"LeftShift": 59,
"RightShift": 60,
"Enter": 66,
"Space": 62,
"Tab": 61,
"Delete": 112, // KEYCODE_FORWARD_DEL
"End": 123,
"Home": 122,
"Insert": 124,
"PageDown": 93,
"PageUp": 92,
"Down": 20,
"Left": 21,
"Right": 22,
"Up": 19,
"Escape": 111,
"Backspace": 67, // KEYCODE_DEL
"Apostrophe": 75,
"Minus": 69,
"Slash": 76,
"Semicolon": 74,
"Equal": 70,
"LeftBracket": 71,
"Backslash": 73,
"RightBracket": 72,
"GraveAccent": 68,
"NumLock": 143,
"Pause": 121, // KEYCODE_BREAK
"PrintScreen": 120, // KEYCODE_SYSRQ
"ScrollLock": 116,
"Menu": 82,
"KPDecimal": 158,
"KPDivide": 154,
"KPMultiply": 155,
"KPSubtract": 156,
"KPAdd": 157,
"KPEnter": 160,
"KPEqual": 161,
androidKeyToDriverKeyName = map[int]string{
55: "KeyComma",
56: "KeyPeriod",
57: "KeyLeftAlt",
58: "KeyRightAlt",
115: "KeyCapsLock",
113: "KeyLeftControl",
114: "KeyRightControl",
59: "KeyLeftShift",
60: "KeyRightShift",
66: "KeyEnter",
62: "KeySpace",
61: "KeyTab",
112: "KeyDelete", // KEYCODE_FORWARD_DEL
123: "KeyEnd",
122: "KeyHome",
124: "KeyInsert",
93: "KeyPageDown",
92: "KeyPageUp",
20: "KeyDown",
21: "KeyLeft",
22: "KeyRight",
19: "KeyUp",
111: "KeyEscape",
67: "KeyBackspace", // KEYCODE_DEL
75: "KeyApostrophe",
69: "KeyMinus",
76: "KeySlash",
74: "KeySemicolon",
70: "KeyEqual",
71: "KeyLeftBracket",
73: "KeyBackslash",
72: "KeyRightBracket",
68: "KeyGraveAccent",
143: "KeyNumLock",
121: "KeyPause", // KEYCODE_BREAK
120: "KeyPrintScreen", // KEYCODE_SYSRQ
116: "KeyScrollLock",
82: "KeyMenu",
158: "KeyKPDecimal",
154: "KeyKPDivide",
155: "KeyKPMultiply",
156: "KeyKPSubtract",
157: "KeyKPAdd",
160: "KeyKPEnter",
161: "KeyKPEqual",
}
nameToJSKey = map[string]string{
@ -195,20 +195,20 @@ func init() {
// ASCII: 0 - 9
for c := '0'; c <= '9'; c++ {
nameToGLFWKey[string(c)] = glfw.Key0 + glfw.Key(c) - '0'
nameToAndroidKey[string(c)] = int(7 + c - '0')
androidKeyToDriverKeyName[7+int(c)-'0'] = string(c)
nameToJSKey[string(c)] = "Digit" + string(c)
}
// ASCII: A - Z
for c := 'A'; c <= 'Z'; c++ {
nameToGLFWKey[string(c)] = glfw.KeyA + glfw.Key(c) - 'A'
nameToAndroidKey[string(c)] = int(29 + c - 'A')
androidKeyToDriverKeyName[29+int(c)-'A'] = string(c)
nameToJSKey[string(c)] = "Key" + string(c)
}
// Function keys
for i := 1; i <= 12; i++ {
name := "F" + strconv.Itoa(i)
nameToGLFWKey[name] = glfw.KeyF1 + glfw.Key(i) - 1
nameToAndroidKey[name] = 131 + i - 1
androidKeyToDriverKeyName[131+i-1] = name
nameToJSKey[name] = name
}
// Numpad
@ -216,7 +216,7 @@ func init() {
for c := '0'; c <= '9'; c++ {
name := "KP" + string(c)
nameToGLFWKey[name] = glfw.KeyKP0 + glfw.Key(c) - '0'
nameToAndroidKey[name] = int(144 + c - '0')
androidKeyToDriverKeyName[144+int(c)-'0'] = name
nameToJSKey[name] = "Numpad" + string(c)
}
}
@ -452,8 +452,8 @@ import (
"github.com/hajimehoshi/ebiten/internal/driver"
)
var androidKeyToDriverKey = map[int]driver.Key{
{{range $name, $code := .NameToAndroidKey}}{{$code}}: driver.Key{{$name}},
var androidKeyToDriverKeyName = map[int]driver.Key{
{{range $key, $name := .AndroidKeyToDriverKeyName}}{{$key}}: driver.Key{{$name}},
{{end}}
}
`
@ -621,7 +621,7 @@ func main() {
EbitenKeyNamesWithoutMods []string
DriverKeyNames []string
NameToGLFWKey map[string]glfw.Key
NameToAndroidKey map[string]int
AndroidKeyToDriverKeyName map[int]string
}{
License: license,
DoNotEdit: doNotEdit,
@ -632,7 +632,7 @@ func main() {
EbitenKeyNamesWithoutMods: ebitenKeyNamesWithoutMods,
DriverKeyNames: driverKeyNames,
NameToGLFWKey: nameToGLFWKey,
NameToAndroidKey: nameToAndroidKey,
AndroidKeyToDriverKeyName: androidKeyToDriverKeyName,
}); err != nil {
log.Fatal(err)
}

View File

@ -20,7 +20,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/driver"
)
var androidKeyToDriverKey = map[int]driver.Key{
var androidKeyToDriverKeyName = map[int]driver.Key{
7: driver.Key0,
8: driver.Key1,
9: driver.Key2,
@ -31,27 +31,70 @@ var androidKeyToDriverKey = map[int]driver.Key{
14: driver.Key7,
15: driver.Key8,
16: driver.Key9,
19: driver.KeyKeyUp,
20: driver.KeyKeyDown,
21: driver.KeyKeyLeft,
22: driver.KeyKeyRight,
29: driver.KeyA,
75: driver.KeyApostrophe,
30: driver.KeyB,
73: driver.KeyBackslash,
67: driver.KeyBackspace,
31: driver.KeyC,
115: driver.KeyCapsLock,
55: driver.KeyComma,
32: driver.KeyD,
112: driver.KeyDelete,
20: driver.KeyDown,
33: driver.KeyE,
123: driver.KeyEnd,
66: driver.KeyEnter,
70: driver.KeyEqual,
111: driver.KeyEscape,
34: driver.KeyF,
35: driver.KeyG,
36: driver.KeyH,
37: driver.KeyI,
38: driver.KeyJ,
39: driver.KeyK,
40: driver.KeyL,
41: driver.KeyM,
42: driver.KeyN,
43: driver.KeyO,
44: driver.KeyP,
45: driver.KeyQ,
46: driver.KeyR,
47: driver.KeyS,
48: driver.KeyT,
49: driver.KeyU,
50: driver.KeyV,
51: driver.KeyW,
52: driver.KeyX,
53: driver.KeyY,
54: driver.KeyZ,
55: driver.KeyKeyComma,
56: driver.KeyKeyPeriod,
57: driver.KeyKeyLeftAlt,
58: driver.KeyKeyRightAlt,
59: driver.KeyKeyLeftShift,
60: driver.KeyKeyRightShift,
61: driver.KeyKeyTab,
62: driver.KeyKeySpace,
66: driver.KeyKeyEnter,
67: driver.KeyKeyBackspace,
68: driver.KeyKeyGraveAccent,
69: driver.KeyKeyMinus,
70: driver.KeyKeyEqual,
71: driver.KeyKeyLeftBracket,
72: driver.KeyKeyRightBracket,
73: driver.KeyKeyBackslash,
74: driver.KeyKeySemicolon,
75: driver.KeyKeyApostrophe,
76: driver.KeyKeySlash,
82: driver.KeyKeyMenu,
92: driver.KeyKeyPageUp,
93: driver.KeyKeyPageDown,
111: driver.KeyKeyEscape,
112: driver.KeyKeyDelete,
113: driver.KeyKeyLeftControl,
114: driver.KeyKeyRightControl,
115: driver.KeyKeyCapsLock,
116: driver.KeyKeyScrollLock,
120: driver.KeyKeyPrintScreen,
121: driver.KeyKeyPause,
122: driver.KeyKeyHome,
123: driver.KeyKeyEnd,
124: driver.KeyKeyInsert,
131: driver.KeyF1,
140: driver.KeyF10,
141: driver.KeyF11,
142: driver.KeyF12,
132: driver.KeyF2,
133: driver.KeyF3,
134: driver.KeyF4,
@ -60,14 +103,10 @@ var androidKeyToDriverKey = map[int]driver.Key{
137: driver.KeyF7,
138: driver.KeyF8,
139: driver.KeyF9,
35: driver.KeyG,
68: driver.KeyGraveAccent,
36: driver.KeyH,
122: driver.KeyHome,
37: driver.KeyI,
124: driver.KeyInsert,
38: driver.KeyJ,
39: driver.KeyK,
140: driver.KeyF10,
141: driver.KeyF11,
142: driver.KeyF12,
143: driver.KeyKeyNumLock,
144: driver.KeyKP0,
145: driver.KeyKP1,
146: driver.KeyKP2,
@ -78,50 +117,11 @@ var androidKeyToDriverKey = map[int]driver.Key{
151: driver.KeyKP7,
152: driver.KeyKP8,
153: driver.KeyKP9,
157: driver.KeyKPAdd,
158: driver.KeyKPDecimal,
154: driver.KeyKPDivide,
160: driver.KeyKPEnter,
161: driver.KeyKPEqual,
155: driver.KeyKPMultiply,
156: driver.KeyKPSubtract,
40: driver.KeyL,
21: driver.KeyLeft,
57: driver.KeyLeftAlt,
71: driver.KeyLeftBracket,
113: driver.KeyLeftControl,
59: driver.KeyLeftShift,
41: driver.KeyM,
82: driver.KeyMenu,
69: driver.KeyMinus,
42: driver.KeyN,
143: driver.KeyNumLock,
43: driver.KeyO,
44: driver.KeyP,
93: driver.KeyPageDown,
92: driver.KeyPageUp,
121: driver.KeyPause,
56: driver.KeyPeriod,
120: driver.KeyPrintScreen,
45: driver.KeyQ,
46: driver.KeyR,
22: driver.KeyRight,
58: driver.KeyRightAlt,
72: driver.KeyRightBracket,
114: driver.KeyRightControl,
60: driver.KeyRightShift,
47: driver.KeyS,
116: driver.KeyScrollLock,
74: driver.KeySemicolon,
76: driver.KeySlash,
62: driver.KeySpace,
48: driver.KeyT,
61: driver.KeyTab,
49: driver.KeyU,
19: driver.KeyUp,
50: driver.KeyV,
51: driver.KeyW,
52: driver.KeyX,
53: driver.KeyY,
54: driver.KeyZ,
154: driver.KeyKeyKPDivide,
155: driver.KeyKeyKPMultiply,
156: driver.KeyKeyKPSubtract,
157: driver.KeyKeyKPAdd,
158: driver.KeyKeyKPDecimal,
160: driver.KeyKeyKPEnter,
161: driver.KeyKeyKPEqual,
}