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

View File

@ -20,7 +20,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/driver" "github.com/hajimehoshi/ebiten/internal/driver"
) )
var androidKeyToDriverKey = map[int]driver.Key{ var androidKeyToDriverKeyName = map[int]driver.Key{
7: driver.Key0, 7: driver.Key0,
8: driver.Key1, 8: driver.Key1,
9: driver.Key2, 9: driver.Key2,
@ -31,27 +31,70 @@ var androidKeyToDriverKey = map[int]driver.Key{
14: driver.Key7, 14: driver.Key7,
15: driver.Key8, 15: driver.Key8,
16: driver.Key9, 16: driver.Key9,
19: driver.KeyKeyUp,
20: driver.KeyKeyDown,
21: driver.KeyKeyLeft,
22: driver.KeyKeyRight,
29: driver.KeyA, 29: driver.KeyA,
75: driver.KeyApostrophe,
30: driver.KeyB, 30: driver.KeyB,
73: driver.KeyBackslash,
67: driver.KeyBackspace,
31: driver.KeyC, 31: driver.KeyC,
115: driver.KeyCapsLock,
55: driver.KeyComma,
32: driver.KeyD, 32: driver.KeyD,
112: driver.KeyDelete,
20: driver.KeyDown,
33: driver.KeyE, 33: driver.KeyE,
123: driver.KeyEnd,
66: driver.KeyEnter,
70: driver.KeyEqual,
111: driver.KeyEscape,
34: driver.KeyF, 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, 131: driver.KeyF1,
140: driver.KeyF10,
141: driver.KeyF11,
142: driver.KeyF12,
132: driver.KeyF2, 132: driver.KeyF2,
133: driver.KeyF3, 133: driver.KeyF3,
134: driver.KeyF4, 134: driver.KeyF4,
@ -60,14 +103,10 @@ var androidKeyToDriverKey = map[int]driver.Key{
137: driver.KeyF7, 137: driver.KeyF7,
138: driver.KeyF8, 138: driver.KeyF8,
139: driver.KeyF9, 139: driver.KeyF9,
35: driver.KeyG, 140: driver.KeyF10,
68: driver.KeyGraveAccent, 141: driver.KeyF11,
36: driver.KeyH, 142: driver.KeyF12,
122: driver.KeyHome, 143: driver.KeyKeyNumLock,
37: driver.KeyI,
124: driver.KeyInsert,
38: driver.KeyJ,
39: driver.KeyK,
144: driver.KeyKP0, 144: driver.KeyKP0,
145: driver.KeyKP1, 145: driver.KeyKP1,
146: driver.KeyKP2, 146: driver.KeyKP2,
@ -78,50 +117,11 @@ var androidKeyToDriverKey = map[int]driver.Key{
151: driver.KeyKP7, 151: driver.KeyKP7,
152: driver.KeyKP8, 152: driver.KeyKP8,
153: driver.KeyKP9, 153: driver.KeyKP9,
157: driver.KeyKPAdd, 154: driver.KeyKeyKPDivide,
158: driver.KeyKPDecimal, 155: driver.KeyKeyKPMultiply,
154: driver.KeyKPDivide, 156: driver.KeyKeyKPSubtract,
160: driver.KeyKPEnter, 157: driver.KeyKeyKPAdd,
161: driver.KeyKPEqual, 158: driver.KeyKeyKPDecimal,
155: driver.KeyKPMultiply, 160: driver.KeyKeyKPEnter,
156: driver.KeyKPSubtract, 161: driver.KeyKeyKPEqual,
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,
} }