From 7389f9ddb22e6839fb21e0de37eeb50dce8213ce Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 12 Mar 2024 12:10:19 +0900 Subject: [PATCH] ebiten: add KeyIntlBackslash Updates #2921 --- genkeys.go | 15 ++++++++++++--- internal/ui/keys.go | 3 +++ internal/ui/keys_glfw.go | 1 + internal/ui/keys_js.go | 1 + keys.go | 7 +++++++ mobile/ebitenmobileview/keys_ios.go | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/genkeys.go b/genkeys.go index a21f00f2b..bc0278d66 100644 --- a/genkeys.go +++ b/genkeys.go @@ -140,9 +140,17 @@ func init() { "NumpadSubtract": "KPSubtract", "NumpadEnter": "KPEnter", "NumpadEqual": "KPEqual", + "IntlBackslash": "World1", } // https://developer.android.com/reference/android/view/KeyEvent + // + // Android doesn't distinguish these keys: + // - a US backslash key (HID: 0x31), + // - an international pound/tilde key (HID: 0x32), and + // - an international backslash key (HID: 0x64). + // These are mapped to the same key code KEYCODE_BACKSLASH (73). + // See https://source.android.com/docs/core/interaction/input/keyboard-devices androidKeyToUIKeyName = map[int]string{ 55: "Comma", 56: "Period", @@ -204,16 +212,16 @@ func init() { 0x35: "Backquote", // These three keys are: - // - US backslash-pipe key (above return), - // - non-US backslash key (next to left shift; on German layout this is the <>| key), and + // - US backslash-pipe key, and // - non-US hashmark key (bottom left of return; on German layout, this is the #' key). // On US layout configurations, they all map to the same characters - the backslash. // // See also: https://www.w3.org/TR/uievents-code/#keyboard-102 0x31: "Backslash", // UIKeyboardHIDUsageKeyboardBackslash - 0x64: "Backslash", // UIKeyboardHIDUsageKeyboardNonUSBackslash 0x32: "Backslash", // UIKeyboardHIDUsageKeyboardNonUSPound + 0x64: "IntlBackslash", // UIKeyboardHIDUsageKeyboardNonUSBackslash + 0x2A: "Backspace", 0x2F: "BracketLeft", 0x30: "BracketRight", @@ -326,6 +334,7 @@ func init() { "NumpadEqual": "NumpadEqual", "MetaLeft": "MetaLeft", "MetaRight": "MetaRight", + "IntlBackslash": "IntlBackslash", } const ( diff --git a/internal/ui/keys.go b/internal/ui/keys.go index b0b4118d5..59bdcab77 100644 --- a/internal/ui/keys.go +++ b/internal/ui/keys.go @@ -106,6 +106,7 @@ const ( KeyF24 KeyHome KeyInsert + KeyIntlBackslash KeyMetaLeft KeyMetaRight KeyMinus @@ -315,6 +316,8 @@ func (k Key) String() string { return "KeyHome" case KeyInsert: return "KeyInsert" + case KeyIntlBackslash: + return "KeyIntlBackslash" case KeyMetaLeft: return "KeyMetaLeft" case KeyMetaRight: diff --git a/internal/ui/keys_glfw.go b/internal/ui/keys_glfw.go index 96a273cf6..37af13b49 100644 --- a/internal/ui/keys_glfw.go +++ b/internal/ui/keys_glfw.go @@ -89,6 +89,7 @@ var uiKeyToGLFWKey = map[Key]glfw.Key{ KeyHome: glfw.KeyHome, KeyI: glfw.KeyI, KeyInsert: glfw.KeyInsert, + KeyIntlBackslash: glfw.KeyWorld1, KeyJ: glfw.KeyJ, KeyK: glfw.KeyK, KeyL: glfw.KeyL, diff --git a/internal/ui/keys_js.go b/internal/ui/keys_js.go index 26c3ea73f..e68203178 100644 --- a/internal/ui/keys_js.go +++ b/internal/ui/keys_js.go @@ -87,6 +87,7 @@ var uiKeyToJSCode = map[Key]js.Value{ KeyHome: js.ValueOf("Home"), KeyI: js.ValueOf("KeyI"), KeyInsert: js.ValueOf("Insert"), + KeyIntlBackslash: js.ValueOf("IntlBackslash"), KeyJ: js.ValueOf("KeyJ"), KeyK: js.ValueOf("KeyK"), KeyL: js.ValueOf("KeyL"), diff --git a/keys.go b/keys.go index 01f2c7447..e7a1fa82b 100644 --- a/keys.go +++ b/keys.go @@ -113,6 +113,7 @@ const ( KeyF24 Key = Key(ui.KeyF24) KeyHome Key = Key(ui.KeyHome) KeyInsert Key = Key(ui.KeyInsert) + KeyIntlBackslash Key = Key(ui.KeyIntlBackslash) KeyMetaLeft Key = Key(ui.KeyMetaLeft) KeyMetaRight Key = Key(ui.KeyMetaRight) KeyMinus Key = Key(ui.KeyMinus) @@ -365,6 +366,8 @@ func (k Key) isValid() bool { return true case KeyInsert: return true + case KeyIntlBackslash: + return true case KeyMeta: return true case KeyMetaLeft: @@ -618,6 +621,8 @@ func (k Key) String() string { return "Home" case KeyInsert: return "Insert" + case KeyIntlBackslash: + return "IntlBackslash" case KeyMeta: return "Meta" case KeyMetaLeft: @@ -892,6 +897,8 @@ func keyNameToKeyCode(name string) (Key, bool) { return KeyHome, true case "insert": return KeyInsert, true + case "intlbackslash": + return KeyIntlBackslash, true case "kp0": return KeyKP0, true case "kp1": diff --git a/mobile/ebitenmobileview/keys_ios.go b/mobile/ebitenmobileview/keys_ios.go index 2b16318fa..0f2ed24a5 100644 --- a/mobile/ebitenmobileview/keys_ios.go +++ b/mobile/ebitenmobileview/keys_ios.go @@ -117,7 +117,7 @@ var iosKeyToUIKey = map[int]ui.Key{ 97: ui.KeyNumpad9, 98: ui.KeyNumpad0, 99: ui.KeyNumpadDecimal, - 100: ui.KeyBackslash, + 100: ui.KeyIntlBackslash, 103: ui.KeyNumpadEqual, 104: ui.KeyF13, 105: ui.KeyF14,