ebiten: Add KeySuper

Fixes #1382
This commit is contained in:
Hajime Hoshi 2020-10-11 18:33:40 +09:00
parent 8e46769284
commit 5ee3fdf628
8 changed files with 46 additions and 3 deletions

View File

@ -144,6 +144,8 @@ func init() {
157: "KPAdd", 157: "KPAdd",
160: "KPEnter", 160: "KPEnter",
161: "KPEqual", 161: "KPEqual",
117: "LeftSuper", // KEYCODE_META_LEFT
118: "RightSuper", // KEYCODE_META_RIGHT
} }
gbuildKeyToDriverKeyName = map[key.Code]string{ gbuildKeyToDriverKeyName = map[key.Code]string{
@ -189,6 +191,8 @@ func init() {
key.CodeKeypadPlusSign: "KPAdd", key.CodeKeypadPlusSign: "KPAdd",
key.CodeKeypadEnter: "KPEnter", key.CodeKeypadEnter: "KPEnter",
key.CodeKeypadEqualSign: "KPEqual", key.CodeKeypadEqualSign: "KPEqual",
key.CodeLeftGUI: "LeftSuper",
key.CodeRightGUI: "RightSuper",
// Missing keys: // Missing keys:
// driver.KeyPrintScreen // driver.KeyPrintScreen
@ -242,6 +246,8 @@ func init() {
"KPAdd": "NumpadAdd", "KPAdd": "NumpadAdd",
"KPEnter": "NumpadEnter", "KPEnter": "NumpadEnter",
"KPEqual": "NumpadEqual", "KPEqual": "NumpadEqual",
"LeftSuper": "MetaLeft",
"RightSuper": "MetaRight",
} }
// ASCII: 0 - 9 // ASCII: 0 - 9
@ -290,6 +296,7 @@ func init() {
} }
func init() { func init() {
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
// TODO: How should we treat modifier keys? Now 'left' modifier keys are available. // TODO: How should we treat modifier keys? Now 'left' modifier keys are available.
edgeKeyCodeToName = map[int]string{ edgeKeyCodeToName = map[int]string{
0xbc: "Comma", 0xbc: "Comma",
@ -331,6 +338,8 @@ func init() {
0x13: "Pause", 0x13: "Pause",
0x91: "ScrollLock", 0x91: "ScrollLock",
0x5d: "Menu", 0x5d: "Menu",
0x5b: "LeftSuper", // "OSLeft" for macOS 10.10 or newer
0xe0: "LeftSuper", // "DOM_VK_META" for macOS 10.9 or older
// On Edge, this key does not work. PrintScreen works only on keyup event. // On Edge, this key does not work. PrintScreen works only on keyup event.
// 0x2C: "PrintScreen", // 0x2C: "PrintScreen",
@ -380,7 +389,8 @@ const (
{{end}} KeyAlt Key = Key(driver.KeyReserved0) {{end}} KeyAlt Key = Key(driver.KeyReserved0)
KeyControl Key = Key(driver.KeyReserved1) KeyControl Key = Key(driver.KeyReserved1)
KeyShift Key = Key(driver.KeyReserved2) KeyShift Key = Key(driver.KeyReserved2)
KeyMax Key = KeyShift KeySuper Key = Key(driver.KeyReserved3)
KeyMax Key = KeySuper
) )
func (k Key) isValid() bool { func (k Key) isValid() bool {
@ -430,6 +440,7 @@ const (
{{end}} KeyReserved0 {{end}} KeyReserved0
KeyReserved1 KeyReserved1
KeyReserved2 KeyReserved2
KeyReserved3
) )
func (k Key) String() string { func (k Key) String() string {
@ -652,7 +663,7 @@ func main() {
driverKeyNames := []string{} driverKeyNames := []string{}
for name := range driverKeyNameToJSKey { for name := range driverKeyNameToJSKey {
driverKeyNames = append(driverKeyNames, name) driverKeyNames = append(driverKeyNames, name)
if !strings.HasSuffix(name, "Alt") && !strings.HasSuffix(name, "Control") && !strings.HasSuffix(name, "Shift") { if !strings.HasSuffix(name, "Alt") && !strings.HasSuffix(name, "Control") && !strings.HasSuffix(name, "Shift") && !strings.HasSuffix(name, "Super") {
ebitenKeyNames = append(ebitenKeyNames, name) ebitenKeyNames = append(ebitenKeyNames, name)
ebitenKeyNamesWithoutMods = append(ebitenKeyNamesWithoutMods, name) ebitenKeyNamesWithoutMods = append(ebitenKeyNamesWithoutMods, name)
continue continue
@ -669,6 +680,10 @@ func main() {
ebitenKeyNames = append(ebitenKeyNames, "Shift") ebitenKeyNames = append(ebitenKeyNames, "Shift")
continue continue
} }
if name == "LeftSuper" {
ebitenKeyNames = append(ebitenKeyNames, "Super")
continue
}
} }
sort.Slice(ebitenKeyNames, keyNamesLess(ebitenKeyNames)) sort.Slice(ebitenKeyNames, keyNamesLess(ebitenKeyNames))

View File

@ -66,6 +66,8 @@ func IsKeyPressed(key Key) bool {
keys = []driver.Key{driver.KeyLeftControl, driver.KeyRightControl} keys = []driver.Key{driver.KeyLeftControl, driver.KeyRightControl}
case KeyShift: case KeyShift:
keys = []driver.Key{driver.KeyLeftShift, driver.KeyRightShift} keys = []driver.Key{driver.KeyLeftShift, driver.KeyRightShift}
case KeySuper:
keys = []driver.Key{driver.KeyLeftSuper, driver.KeyRightSuper}
default: default:
keys = []driver.Key{driver.Key(key)} keys = []driver.Key{driver.Key(key)}
} }

View File

@ -107,6 +107,7 @@ const (
KeyLeftBracket KeyLeftBracket
KeyLeftControl KeyLeftControl
KeyLeftShift KeyLeftShift
KeyLeftSuper
KeyMenu KeyMenu
KeyMinus KeyMinus
KeyNumLock KeyNumLock
@ -120,6 +121,7 @@ const (
KeyRightBracket KeyRightBracket
KeyRightControl KeyRightControl
KeyRightShift KeyRightShift
KeyRightSuper
KeyScrollLock KeyScrollLock
KeySemicolon KeySemicolon
KeySlash KeySlash
@ -129,6 +131,7 @@ const (
KeyReserved0 KeyReserved0
KeyReserved1 KeyReserved1
KeyReserved2 KeyReserved2
KeyReserved3
) )
func (k Key) String() string { func (k Key) String() string {
@ -301,6 +304,8 @@ func (k Key) String() string {
return "KeyLeftControl" return "KeyLeftControl"
case KeyLeftShift: case KeyLeftShift:
return "KeyLeftShift" return "KeyLeftShift"
case KeyLeftSuper:
return "KeyLeftSuper"
case KeyMenu: case KeyMenu:
return "KeyMenu" return "KeyMenu"
case KeyMinus: case KeyMinus:
@ -327,6 +332,8 @@ func (k Key) String() string {
return "KeyRightControl" return "KeyRightControl"
case KeyRightShift: case KeyRightShift:
return "KeyRightShift" return "KeyRightShift"
case KeyRightSuper:
return "KeyRightSuper"
case KeyScrollLock: case KeyScrollLock:
return "KeyScrollLock" return "KeyScrollLock"
case KeySemicolon: case KeySemicolon:

View File

@ -110,6 +110,7 @@ var glfwKeyToDriverKey = map[glfw.Key]driver.Key{
glfw.KeyLeftBracket: driver.KeyLeftBracket, glfw.KeyLeftBracket: driver.KeyLeftBracket,
glfw.KeyLeftControl: driver.KeyLeftControl, glfw.KeyLeftControl: driver.KeyLeftControl,
glfw.KeyLeftShift: driver.KeyLeftShift, glfw.KeyLeftShift: driver.KeyLeftShift,
glfw.KeyLeftSuper: driver.KeyLeftSuper,
glfw.KeyMenu: driver.KeyMenu, glfw.KeyMenu: driver.KeyMenu,
glfw.KeyMinus: driver.KeyMinus, glfw.KeyMinus: driver.KeyMinus,
glfw.KeyNumLock: driver.KeyNumLock, glfw.KeyNumLock: driver.KeyNumLock,
@ -123,6 +124,7 @@ var glfwKeyToDriverKey = map[glfw.Key]driver.Key{
glfw.KeyRightBracket: driver.KeyRightBracket, glfw.KeyRightBracket: driver.KeyRightBracket,
glfw.KeyRightControl: driver.KeyRightControl, glfw.KeyRightControl: driver.KeyRightControl,
glfw.KeyRightShift: driver.KeyRightShift, glfw.KeyRightShift: driver.KeyRightShift,
glfw.KeyRightSuper: driver.KeyRightSuper,
glfw.KeyScrollLock: driver.KeyScrollLock, glfw.KeyScrollLock: driver.KeyScrollLock,
glfw.KeySemicolon: driver.KeySemicolon, glfw.KeySemicolon: driver.KeySemicolon,
glfw.KeySlash: driver.KeySlash, glfw.KeySlash: driver.KeySlash,
@ -216,6 +218,7 @@ var driverKeyToGLFWKey = map[driver.Key]glfw.Key{
driver.KeyLeftBracket: glfw.KeyLeftBracket, driver.KeyLeftBracket: glfw.KeyLeftBracket,
driver.KeyLeftControl: glfw.KeyLeftControl, driver.KeyLeftControl: glfw.KeyLeftControl,
driver.KeyLeftShift: glfw.KeyLeftShift, driver.KeyLeftShift: glfw.KeyLeftShift,
driver.KeyLeftSuper: glfw.KeyLeftSuper,
driver.KeyMenu: glfw.KeyMenu, driver.KeyMenu: glfw.KeyMenu,
driver.KeyMinus: glfw.KeyMinus, driver.KeyMinus: glfw.KeyMinus,
driver.KeyNumLock: glfw.KeyNumLock, driver.KeyNumLock: glfw.KeyNumLock,
@ -229,6 +232,7 @@ var driverKeyToGLFWKey = map[driver.Key]glfw.Key{
driver.KeyRightBracket: glfw.KeyRightBracket, driver.KeyRightBracket: glfw.KeyRightBracket,
driver.KeyRightControl: glfw.KeyRightControl, driver.KeyRightControl: glfw.KeyRightControl,
driver.KeyRightShift: glfw.KeyRightShift, driver.KeyRightShift: glfw.KeyRightShift,
driver.KeyRightSuper: glfw.KeyRightSuper,
driver.KeyScrollLock: glfw.KeyScrollLock, driver.KeyScrollLock: glfw.KeyScrollLock,
driver.KeySemicolon: glfw.KeySemicolon, driver.KeySemicolon: glfw.KeySemicolon,
driver.KeySlash: glfw.KeySlash, driver.KeySlash: glfw.KeySlash,

View File

@ -91,6 +91,7 @@ var driverKeyToJSKey = map[driver.Key]string{
driver.KeyLeftBracket: "BracketLeft", driver.KeyLeftBracket: "BracketLeft",
driver.KeyLeftControl: "ControlLeft", driver.KeyLeftControl: "ControlLeft",
driver.KeyLeftShift: "ShiftLeft", driver.KeyLeftShift: "ShiftLeft",
driver.KeyLeftSuper: "MetaLeft",
driver.KeyM: "KeyM", driver.KeyM: "KeyM",
driver.KeyMenu: "ContextMenu", driver.KeyMenu: "ContextMenu",
driver.KeyMinus: "Minus", driver.KeyMinus: "Minus",
@ -110,6 +111,7 @@ var driverKeyToJSKey = map[driver.Key]string{
driver.KeyRightBracket: "BracketRight", driver.KeyRightBracket: "BracketRight",
driver.KeyRightControl: "ControlRight", driver.KeyRightControl: "ControlRight",
driver.KeyRightShift: "ShiftRight", driver.KeyRightShift: "ShiftRight",
driver.KeyRightSuper: "MetaRight",
driver.KeyS: "KeyS", driver.KeyS: "KeyS",
driver.KeyScrollLock: "ScrollLock", driver.KeyScrollLock: "ScrollLock",
driver.KeySemicolon: "Semicolon", driver.KeySemicolon: "Semicolon",
@ -183,6 +185,7 @@ var edgeKeyCodeToDriverKey = map[int]driver.Key{
88: driver.KeyX, 88: driver.KeyX,
89: driver.KeyY, 89: driver.KeyY,
90: driver.KeyZ, 90: driver.KeyZ,
91: driver.KeyLeftSuper,
93: driver.KeyMenu, 93: driver.KeyMenu,
96: driver.KeyKP0, 96: driver.KeyKP0,
97: driver.KeyKP1, 97: driver.KeyKP1,
@ -224,4 +227,5 @@ var edgeKeyCodeToDriverKey = map[int]driver.Key{
220: driver.KeyBackslash, 220: driver.KeyBackslash,
221: driver.KeyRightBracket, 221: driver.KeyRightBracket,
222: driver.KeyApostrophe, 222: driver.KeyApostrophe,
224: driver.KeyLeftSuper,
} }

View File

@ -120,7 +120,9 @@ var gbuildKeyToDriverKey = map[key.Code]driver.Key{
key.CodeLeftControl: driver.KeyLeftControl, key.CodeLeftControl: driver.KeyLeftControl,
key.CodeLeftShift: driver.KeyLeftShift, key.CodeLeftShift: driver.KeyLeftShift,
key.CodeLeftAlt: driver.KeyLeftAlt, key.CodeLeftAlt: driver.KeyLeftAlt,
key.CodeLeftGUI: driver.KeyLeftSuper,
key.CodeRightControl: driver.KeyRightControl, key.CodeRightControl: driver.KeyRightControl,
key.CodeRightShift: driver.KeyRightShift, key.CodeRightShift: driver.KeyRightShift,
key.CodeRightAlt: driver.KeyRightAlt, key.CodeRightAlt: driver.KeyRightAlt,
key.CodeRightGUI: driver.KeyRightSuper,
} }

View File

@ -129,7 +129,8 @@ const (
KeyAlt Key = Key(driver.KeyReserved0) KeyAlt Key = Key(driver.KeyReserved0)
KeyControl Key = Key(driver.KeyReserved1) KeyControl Key = Key(driver.KeyReserved1)
KeyShift Key = Key(driver.KeyReserved2) KeyShift Key = Key(driver.KeyReserved2)
KeyMax Key = KeyShift KeySuper Key = Key(driver.KeyReserved3)
KeyMax Key = KeySuper
) )
func (k Key) isValid() bool { func (k Key) isValid() bool {
@ -330,6 +331,8 @@ func (k Key) isValid() bool {
return true return true
case KeySpace: case KeySpace:
return true return true
case KeySuper:
return true
case KeyTab: case KeyTab:
return true return true
case KeyUp: case KeyUp:
@ -541,6 +544,8 @@ func (k Key) String() string {
return "Slash" return "Slash"
case KeySpace: case KeySpace:
return "Space" return "Space"
case KeySuper:
return "Super"
case KeyTab: case KeyTab:
return "Tab" return "Tab"
case KeyUp: case KeyUp:
@ -747,6 +752,8 @@ func keyNameToKeyCode(name string) (Key, bool) {
return KeySlash, true return KeySlash, true
case "space": case "space":
return KeySpace, true return KeySpace, true
case "super":
return KeySuper, true
case "tab": case "tab":
return KeyTab, true return KeyTab, true
case "up": case "up":

View File

@ -89,6 +89,8 @@ var androidKeyToDriverKey = map[int]driver.Key{
114: driver.KeyRightControl, 114: driver.KeyRightControl,
115: driver.KeyCapsLock, 115: driver.KeyCapsLock,
116: driver.KeyScrollLock, 116: driver.KeyScrollLock,
117: driver.KeyLeftSuper,
118: driver.KeyRightSuper,
120: driver.KeyPrintScreen, 120: driver.KeyPrintScreen,
121: driver.KeyPause, 121: driver.KeyPause,
122: driver.KeyHome, 122: driver.KeyHome,