diff --git a/genkeys.go b/genkeys.go index c50b6c743..97141bc2d 100644 --- a/genkeys.go +++ b/genkeys.go @@ -342,6 +342,11 @@ var glfwKeyCodeToKey = map[glfw.Key]driver.Key{ {{range $index, $name := .DriverKeyNames}}glfw.Key{{$name}}: driver.Key{{$name}}, {{end}} } + +var keyCodeToGLFWKey = map[driver.Key]glfw.Key{ +{{range $index, $name := .DriverKeyNames}}driver.Key{{$name}}: glfw.Key{{$name}}, +{{end}} +} ` const uidriverJsKeysTmpl = `{{.License}} diff --git a/internal/uidriver/glfw/input.go b/internal/uidriver/glfw/input.go index 454fe19f0..b9ce69510 100644 --- a/internal/uidriver/glfw/input.go +++ b/internal/uidriver/glfw/input.go @@ -248,14 +248,10 @@ func (i *Input) IsKeyPressed(key driver.Key) bool { if i.keyPressed == nil { i.keyPressed = map[glfw.Key]bool{} } - for gk, k := range glfwKeyCodeToKey { - if k != key { - continue - } - if i.keyPressed[gk] { - r = true - return nil - } + gk, ok := keyCodeToGLFWKey[key] + if ok && i.keyPressed[gk] { + r = true + return nil } return nil }) diff --git a/internal/uidriver/glfw/keys.go b/internal/uidriver/glfw/keys.go index fc14aff07..cef64eacd 100644 --- a/internal/uidriver/glfw/keys.go +++ b/internal/uidriver/glfw/keys.go @@ -131,3 +131,109 @@ var glfwKeyCodeToKey = map[glfw.Key]driver.Key{ glfw.KeyTab: driver.KeyTab, glfw.KeyUp: driver.KeyUp, } + +var keyCodeToGLFWKey = map[driver.Key]glfw.Key{ + driver.Key0: glfw.Key0, + driver.Key1: glfw.Key1, + driver.Key2: glfw.Key2, + driver.Key3: glfw.Key3, + driver.Key4: glfw.Key4, + driver.Key5: glfw.Key5, + driver.Key6: glfw.Key6, + driver.Key7: glfw.Key7, + driver.Key8: glfw.Key8, + driver.Key9: glfw.Key9, + driver.KeyA: glfw.KeyA, + driver.KeyB: glfw.KeyB, + driver.KeyC: glfw.KeyC, + driver.KeyD: glfw.KeyD, + driver.KeyE: glfw.KeyE, + driver.KeyF: glfw.KeyF, + driver.KeyG: glfw.KeyG, + driver.KeyH: glfw.KeyH, + driver.KeyI: glfw.KeyI, + driver.KeyJ: glfw.KeyJ, + driver.KeyK: glfw.KeyK, + driver.KeyL: glfw.KeyL, + driver.KeyM: glfw.KeyM, + driver.KeyN: glfw.KeyN, + driver.KeyO: glfw.KeyO, + driver.KeyP: glfw.KeyP, + driver.KeyQ: glfw.KeyQ, + driver.KeyR: glfw.KeyR, + driver.KeyS: glfw.KeyS, + driver.KeyT: glfw.KeyT, + driver.KeyU: glfw.KeyU, + driver.KeyV: glfw.KeyV, + driver.KeyW: glfw.KeyW, + driver.KeyX: glfw.KeyX, + driver.KeyY: glfw.KeyY, + driver.KeyZ: glfw.KeyZ, + driver.KeyApostrophe: glfw.KeyApostrophe, + driver.KeyBackslash: glfw.KeyBackslash, + driver.KeyBackspace: glfw.KeyBackspace, + driver.KeyCapsLock: glfw.KeyCapsLock, + driver.KeyComma: glfw.KeyComma, + driver.KeyDelete: glfw.KeyDelete, + driver.KeyDown: glfw.KeyDown, + driver.KeyEnd: glfw.KeyEnd, + driver.KeyEnter: glfw.KeyEnter, + driver.KeyEqual: glfw.KeyEqual, + driver.KeyEscape: glfw.KeyEscape, + driver.KeyF1: glfw.KeyF1, + driver.KeyF2: glfw.KeyF2, + driver.KeyF3: glfw.KeyF3, + driver.KeyF4: glfw.KeyF4, + driver.KeyF5: glfw.KeyF5, + driver.KeyF6: glfw.KeyF6, + driver.KeyF7: glfw.KeyF7, + driver.KeyF8: glfw.KeyF8, + driver.KeyF9: glfw.KeyF9, + driver.KeyF10: glfw.KeyF10, + driver.KeyF11: glfw.KeyF11, + driver.KeyF12: glfw.KeyF12, + driver.KeyGraveAccent: glfw.KeyGraveAccent, + driver.KeyHome: glfw.KeyHome, + driver.KeyInsert: glfw.KeyInsert, + driver.KeyKP0: glfw.KeyKP0, + driver.KeyKP1: glfw.KeyKP1, + driver.KeyKP2: glfw.KeyKP2, + driver.KeyKP3: glfw.KeyKP3, + driver.KeyKP4: glfw.KeyKP4, + driver.KeyKP5: glfw.KeyKP5, + driver.KeyKP6: glfw.KeyKP6, + driver.KeyKP7: glfw.KeyKP7, + driver.KeyKP8: glfw.KeyKP8, + driver.KeyKP9: glfw.KeyKP9, + driver.KeyKPAdd: glfw.KeyKPAdd, + driver.KeyKPDecimal: glfw.KeyKPDecimal, + driver.KeyKPDivide: glfw.KeyKPDivide, + driver.KeyKPEnter: glfw.KeyKPEnter, + driver.KeyKPEqual: glfw.KeyKPEqual, + driver.KeyKPMultiply: glfw.KeyKPMultiply, + driver.KeyKPSubtract: glfw.KeyKPSubtract, + driver.KeyLeft: glfw.KeyLeft, + driver.KeyLeftAlt: glfw.KeyLeftAlt, + driver.KeyLeftBracket: glfw.KeyLeftBracket, + driver.KeyLeftControl: glfw.KeyLeftControl, + driver.KeyLeftShift: glfw.KeyLeftShift, + driver.KeyMenu: glfw.KeyMenu, + driver.KeyMinus: glfw.KeyMinus, + driver.KeyNumLock: glfw.KeyNumLock, + driver.KeyPageDown: glfw.KeyPageDown, + driver.KeyPageUp: glfw.KeyPageUp, + driver.KeyPause: glfw.KeyPause, + driver.KeyPeriod: glfw.KeyPeriod, + driver.KeyPrintScreen: glfw.KeyPrintScreen, + driver.KeyRight: glfw.KeyRight, + driver.KeyRightAlt: glfw.KeyRightAlt, + driver.KeyRightBracket: glfw.KeyRightBracket, + driver.KeyRightControl: glfw.KeyRightControl, + driver.KeyRightShift: glfw.KeyRightShift, + driver.KeyScrollLock: glfw.KeyScrollLock, + driver.KeySemicolon: glfw.KeySemicolon, + driver.KeySlash: glfw.KeySlash, + driver.KeySpace: glfw.KeySpace, + driver.KeyTab: glfw.KeyTab, + driver.KeyUp: glfw.KeyUp, +}