From 2f4ca72dbd5b20c1028eb5fa792c8b9a10f5c021 Mon Sep 17 00:00:00 2001 From: Jake Bentvelzen Date: Sun, 22 Apr 2018 02:36:28 +1000 Subject: [PATCH] input: Add Pause and Print Screen buttons (#555) Fixes #579 --- genkeys.go | 10 ++++++++++ internal/input/keys.go | 4 ++++ internal/input/keys_glfw.go | 4 ++++ internal/input/keys_js.go | 15 +++++++++++++++ keys.go | 20 ++++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/genkeys.go b/genkeys.go index 8a6cc370f..792fe96d8 100644 --- a/genkeys.go +++ b/genkeys.go @@ -70,6 +70,10 @@ func init() { "RightBracket": {"BracketRight"}, "GraveAccent": {"Backquote"}, "NumLock": {"NumLock"}, + "Pause": {"Pause"}, + "PrintScreen": {"PrintScreen"}, + "ScrollLock": {"ScrollLock"}, + "Menu": {"ContextMenu"}, } // ASCII: 0 - 9 for c := '0'; c <= '9'; c++ { @@ -135,6 +139,12 @@ func init() { 0x6a: "KPMultiply", 0x6d: "KPSubtract", 0x6b: "KPAdd", + 0x13: "Pause", + 0x91: "ScrollLock", + 0x5d: "Menu", + + // NOTE: On Edge, this key does not work. PrintScreen works only on keyup event, and PrintScreen doesn't work on Edge well. + //0x2C: "PrintScreen", // TODO: On Edge, it is impossible to tell KPEnter and Enter / KPEqual and Equal. // 0x0d: "KPEnter", diff --git a/internal/input/keys.go b/internal/input/keys.go index a9b15d4ca..af4d23668 100644 --- a/internal/input/keys.go +++ b/internal/input/keys.go @@ -102,13 +102,17 @@ const ( KeyKPSubtract KeyLeft KeyLeftBracket + KeyMenu KeyMinus KeyNumLock KeyPageDown KeyPageUp + KeyPause KeyPeriod + KeyPrintScreen KeyRight KeyRightBracket + KeyScrollLock KeySemicolon KeyShift KeySlash diff --git a/internal/input/keys_glfw.go b/internal/input/keys_glfw.go index e41ae4182..922c98b28 100644 --- a/internal/input/keys_glfw.go +++ b/internal/input/keys_glfw.go @@ -107,13 +107,17 @@ var glfwKeyCodeToKey = map[glfw.Key]Key{ glfw.KeyKPSubtract: KeyKPSubtract, glfw.KeyLeft: KeyLeft, glfw.KeyLeftBracket: KeyLeftBracket, + glfw.KeyMenu: KeyMenu, glfw.KeyMinus: KeyMinus, glfw.KeyNumLock: KeyNumLock, glfw.KeyPageDown: KeyPageDown, glfw.KeyPageUp: KeyPageUp, + glfw.KeyPause: KeyPause, glfw.KeyPeriod: KeyPeriod, + glfw.KeyPrintScreen: KeyPrintScreen, glfw.KeyRight: KeyRight, glfw.KeyRightBracket: KeyRightBracket, + glfw.KeyScrollLock: KeyScrollLock, glfw.KeySemicolon: KeySemicolon, glfw.KeySlash: KeySlash, glfw.KeySpace: KeySpace, diff --git a/internal/input/keys_js.go b/internal/input/keys_js.go index 85599a27c..789265a98 100644 --- a/internal/input/keys_js.go +++ b/internal/input/keys_js.go @@ -229,6 +229,9 @@ var keyToCodes = map[Key][]string{ KeyM: { "KeyM", }, + KeyMenu: { + "ContextMenu", + }, KeyMinus: { "Minus", }, @@ -250,9 +253,15 @@ var keyToCodes = map[Key][]string{ KeyPageUp: { "PageUp", }, + KeyPause: { + "Pause", + }, KeyPeriod: { "Period", }, + KeyPrintScreen: { + "PrintScreen", + }, KeyQ: { "KeyQ", }, @@ -268,6 +277,9 @@ var keyToCodes = map[Key][]string{ KeyS: { "KeyS", }, + KeyScrollLock: { + "ScrollLock", + }, KeySemicolon: { "Semicolon", }, @@ -316,6 +328,7 @@ var keyCodeToKeyEdge = map[int]Key{ 16: KeyShift, 17: KeyControl, 18: KeyAlt, + 19: KeyPause, 20: KeyCapsLock, 27: KeyEscape, 32: KeySpace, @@ -365,6 +378,7 @@ var keyCodeToKeyEdge = map[int]Key{ 88: KeyX, 89: KeyY, 90: KeyZ, + 93: KeyMenu, 96: KeyKP0, 97: KeyKP1, 98: KeyKP2, @@ -393,6 +407,7 @@ var keyCodeToKeyEdge = map[int]Key{ 122: KeyF11, 123: KeyF12, 144: KeyNumLock, + 145: KeyScrollLock, 186: KeySemicolon, 187: KeyEqual, 188: KeyComma, diff --git a/keys.go b/keys.go index 8deea2658..d65869863 100644 --- a/keys.go +++ b/keys.go @@ -114,13 +114,17 @@ const ( KeyKPSubtract Key = Key(input.KeyKPSubtract) KeyLeft Key = Key(input.KeyLeft) KeyLeftBracket Key = Key(input.KeyLeftBracket) + KeyMenu Key = Key(input.KeyMenu) KeyMinus Key = Key(input.KeyMinus) KeyNumLock Key = Key(input.KeyNumLock) KeyPageDown Key = Key(input.KeyPageDown) KeyPageUp Key = Key(input.KeyPageUp) + KeyPause Key = Key(input.KeyPause) KeyPeriod Key = Key(input.KeyPeriod) + KeyPrintScreen Key = Key(input.KeyPrintScreen) KeyRight Key = Key(input.KeyRight) KeyRightBracket Key = Key(input.KeyRightBracket) + KeyScrollLock Key = Key(input.KeyScrollLock) KeySemicolon Key = Key(input.KeySemicolon) KeyShift Key = Key(input.KeyShift) KeySlash Key = Key(input.KeySlash) @@ -301,6 +305,8 @@ func (k Key) String() string { return "Left" case KeyLeftBracket: return "LeftBracket" + case KeyMenu: + return "Menu" case KeyMinus: return "Minus" case KeyNumLock: @@ -309,12 +315,18 @@ func (k Key) String() string { return "PageDown" case KeyPageUp: return "PageUp" + case KeyPause: + return "Pause" case KeyPeriod: return "Period" + case KeyPrintScreen: + return "PrintScreen" case KeyRight: return "Right" case KeyRightBracket: return "RightBracket" + case KeyScrollLock: + return "ScrollLock" case KeySemicolon: return "Semicolon" case KeyShift: @@ -499,6 +511,8 @@ func keyNameToKey(name string) (Key, bool) { return KeyLeft, true case "leftbracket": return KeyLeftBracket, true + case "menu": + return KeyMenu, true case "minus": return KeyMinus, true case "numlock": @@ -507,12 +521,18 @@ func keyNameToKey(name string) (Key, bool) { return KeyPageDown, true case "pageup": return KeyPageUp, true + case "pause": + return KeyPause, true case "period": return KeyPeriod, true + case "printscreen": + return KeyPrintScreen, true case "right": return KeyRight, true case "rightbracket": return KeyRightBracket, true + case "scrolllock": + return KeyScrollLock, true case "semicolon": return KeySemicolon, true case "shift":