ui: Add keys (#339)

This commit is contained in:
Hajime Hoshi 2017-04-14 03:09:00 +09:00
parent 0cd692d26a
commit 95cb0133de
5 changed files with 201 additions and 139 deletions

View File

@ -62,6 +62,15 @@ func init() {
"ArrowUp": "Up", "ArrowUp": "Up",
"Escape": "Escape", "Escape": "Escape",
"Backspace": "Backspace", "Backspace": "Backspace",
"Quote": "Apostrophe",
"Minus": "Minus",
"Slash": "Slash",
"Semicolon": "Semicolon",
"Equal": "Equal",
"BracketLeft": "LeftBracket",
"Backslash": "Backslash",
"BracketRight": "RightBracket",
"Backquote": "GraveAccent",
} }
// ASCII: 0 - 9 // ASCII: 0 - 9
for c := '0'; c <= '9'; c++ { for c := '0'; c <= '9'; c++ {
@ -79,8 +88,8 @@ func init() {
func init() { func init() {
keyCodeToNameSafari = map[int]string{ keyCodeToNameSafari = map[int]string{
0xBC: "Comma", 0xbc: "Comma",
0xBE: "Period", 0xbe: "Period",
0x12: "Alt", 0x12: "Alt",
0x14: "CapsLock", 0x14: "CapsLock",
0x11: "Control", 0x11: "Control",
@ -99,7 +108,15 @@ func init() {
0x27: "Right", 0x27: "Right",
0x26: "Up", 0x26: "Up",
0x1B: "Escape", 0x1B: "Escape",
// The keys not listed in the Mozilla site: 0xde: "Apostrophe",
0xbd: "Minus",
0xbf: "Slash",
0xba: "Semicolon",
0xbb: "Equal",
0xdb: "LeftBracket",
0xdc: "Backslash",
0xdd: "RightBracket",
0xc0: "GraveAccent",
0x08: "Backspace", 0x08: "Backspace",
} }
// ASCII: 0 - 9 // ASCII: 0 - 9

View File

@ -56,6 +56,8 @@ const (
KeyY KeyY
KeyZ KeyZ
KeyAlt KeyAlt
KeyApostrophe
KeyBackslash
KeyBackspace KeyBackspace
KeyCapsLock KeyCapsLock
KeyComma KeyComma
@ -64,6 +66,7 @@ const (
KeyDown KeyDown
KeyEnd KeyEnd
KeyEnter KeyEnter
KeyEqual
KeyEscape KeyEscape
KeyF1 KeyF1
KeyF2 KeyF2
@ -77,14 +80,20 @@ const (
KeyF10 KeyF10
KeyF11 KeyF11
KeyF12 KeyF12
KeyGraveAccent
KeyHome KeyHome
KeyInsert KeyInsert
KeyLeft KeyLeft
KeyLeftBracket
KeyMinus
KeyPageDown KeyPageDown
KeyPageUp KeyPageUp
KeyPeriod KeyPeriod
KeyRight KeyRight
KeyRightBracket
KeySemicolon
KeyShift KeyShift
KeySlash
KeySpace KeySpace
KeyTab KeyTab
KeyUp KeyUp

View File

@ -62,6 +62,8 @@ var glfwKeyCodeToKey = map[glfw.Key]Key{
glfw.KeyX: KeyX, glfw.KeyX: KeyX,
glfw.KeyY: KeyY, glfw.KeyY: KeyY,
glfw.KeyZ: KeyZ, glfw.KeyZ: KeyZ,
glfw.KeyApostrophe: KeyApostrophe,
glfw.KeyBackslash: KeyBackslash,
glfw.KeyBackspace: KeyBackspace, glfw.KeyBackspace: KeyBackspace,
glfw.KeyCapsLock: KeyCapsLock, glfw.KeyCapsLock: KeyCapsLock,
glfw.KeyComma: KeyComma, glfw.KeyComma: KeyComma,
@ -69,6 +71,7 @@ var glfwKeyCodeToKey = map[glfw.Key]Key{
glfw.KeyDown: KeyDown, glfw.KeyDown: KeyDown,
glfw.KeyEnd: KeyEnd, glfw.KeyEnd: KeyEnd,
glfw.KeyEnter: KeyEnter, glfw.KeyEnter: KeyEnter,
glfw.KeyEqual: KeyEqual,
glfw.KeyEscape: KeyEscape, glfw.KeyEscape: KeyEscape,
glfw.KeyF1: KeyF1, glfw.KeyF1: KeyF1,
glfw.KeyF2: KeyF2, glfw.KeyF2: KeyF2,
@ -82,13 +85,19 @@ var glfwKeyCodeToKey = map[glfw.Key]Key{
glfw.KeyF10: KeyF10, glfw.KeyF10: KeyF10,
glfw.KeyF11: KeyF11, glfw.KeyF11: KeyF11,
glfw.KeyF12: KeyF12, glfw.KeyF12: KeyF12,
glfw.KeyGraveAccent: KeyGraveAccent,
glfw.KeyHome: KeyHome, glfw.KeyHome: KeyHome,
glfw.KeyInsert: KeyInsert, glfw.KeyInsert: KeyInsert,
glfw.KeyLeft: KeyLeft, glfw.KeyLeft: KeyLeft,
glfw.KeyLeftBracket: KeyLeftBracket,
glfw.KeyMinus: KeyMinus,
glfw.KeyPageDown: KeyPageDown, glfw.KeyPageDown: KeyPageDown,
glfw.KeyPageUp: KeyPageUp, glfw.KeyPageUp: KeyPageUp,
glfw.KeyPeriod: KeyPeriod, glfw.KeyPeriod: KeyPeriod,
glfw.KeyRight: KeyRight, glfw.KeyRight: KeyRight,
glfw.KeyRightBracket: KeyRightBracket,
glfw.KeySemicolon: KeySemicolon,
glfw.KeySlash: KeySlash,
glfw.KeySpace: KeySpace, glfw.KeySpace: KeySpace,
glfw.KeyTab: KeyTab, glfw.KeyTab: KeyTab,
glfw.KeyUp: KeyUp, glfw.KeyUp: KeyUp,

View File

@ -25,7 +25,11 @@ var codeToKey = map[string]Key{
"ArrowLeft": KeyLeft, "ArrowLeft": KeyLeft,
"ArrowRight": KeyRight, "ArrowRight": KeyRight,
"ArrowUp": KeyUp, "ArrowUp": KeyUp,
"Backquote": KeyGraveAccent,
"Backslash": KeyBackslash,
"Backspace": KeyBackspace, "Backspace": KeyBackspace,
"BracketLeft": KeyLeftBracket,
"BracketRight": KeyRightBracket,
"CapsLock": KeyCapsLock, "CapsLock": KeyCapsLock,
"Comma": KeyComma, "Comma": KeyComma,
"ControlLeft": KeyControl, "ControlLeft": KeyControl,
@ -43,6 +47,7 @@ var codeToKey = map[string]Key{
"Digit9": Key9, "Digit9": Key9,
"End": KeyEnd, "End": KeyEnd,
"Enter": KeyEnter, "Enter": KeyEnter,
"Equal": KeyEqual,
"Escape": KeyEscape, "Escape": KeyEscape,
"F1": KeyF1, "F1": KeyF1,
"F10": KeyF10, "F10": KeyF10,
@ -84,11 +89,15 @@ var codeToKey = map[string]Key{
"KeyX": KeyX, "KeyX": KeyX,
"KeyY": KeyY, "KeyY": KeyY,
"KeyZ": KeyZ, "KeyZ": KeyZ,
"Minus": KeyMinus,
"PageDown": KeyPageDown, "PageDown": KeyPageDown,
"PageUp": KeyPageUp, "PageUp": KeyPageUp,
"Period": KeyPeriod, "Period": KeyPeriod,
"Quote": KeyApostrophe,
"Semicolon": KeySemicolon,
"ShiftLeft": KeyShift, "ShiftLeft": KeyShift,
"ShiftRight": KeyShift, "ShiftRight": KeyShift,
"Slash": KeySlash,
"Space": KeySpace, "Space": KeySpace,
"Tab": KeyTab, "Tab": KeyTab,
} }
@ -161,6 +170,15 @@ var keyCodeToKeySafari = map[int]Key{
121: KeyF10, 121: KeyF10,
122: KeyF11, 122: KeyF11,
123: KeyF12, 123: KeyF12,
186: KeySemicolon,
187: KeyEqual,
188: KeyComma, 188: KeyComma,
189: KeyMinus,
190: KeyPeriod, 190: KeyPeriod,
191: KeySlash,
192: KeyGraveAccent,
219: KeyLeftBracket,
220: KeyBackslash,
221: KeyRightBracket,
222: KeyApostrophe,
} }

View File

@ -64,6 +64,8 @@ const (
KeyY = Key(ui.KeyY) KeyY = Key(ui.KeyY)
KeyZ = Key(ui.KeyZ) KeyZ = Key(ui.KeyZ)
KeyAlt = Key(ui.KeyAlt) KeyAlt = Key(ui.KeyAlt)
KeyApostrophe = Key(ui.KeyApostrophe)
KeyBackslash = Key(ui.KeyBackslash)
KeyBackspace = Key(ui.KeyBackspace) KeyBackspace = Key(ui.KeyBackspace)
KeyCapsLock = Key(ui.KeyCapsLock) KeyCapsLock = Key(ui.KeyCapsLock)
KeyComma = Key(ui.KeyComma) KeyComma = Key(ui.KeyComma)
@ -72,6 +74,7 @@ const (
KeyDown = Key(ui.KeyDown) KeyDown = Key(ui.KeyDown)
KeyEnd = Key(ui.KeyEnd) KeyEnd = Key(ui.KeyEnd)
KeyEnter = Key(ui.KeyEnter) KeyEnter = Key(ui.KeyEnter)
KeyEqual = Key(ui.KeyEqual)
KeyEscape = Key(ui.KeyEscape) KeyEscape = Key(ui.KeyEscape)
KeyF1 = Key(ui.KeyF1) KeyF1 = Key(ui.KeyF1)
KeyF2 = Key(ui.KeyF2) KeyF2 = Key(ui.KeyF2)
@ -85,14 +88,20 @@ const (
KeyF10 = Key(ui.KeyF10) KeyF10 = Key(ui.KeyF10)
KeyF11 = Key(ui.KeyF11) KeyF11 = Key(ui.KeyF11)
KeyF12 = Key(ui.KeyF12) KeyF12 = Key(ui.KeyF12)
KeyGraveAccent = Key(ui.KeyGraveAccent)
KeyHome = Key(ui.KeyHome) KeyHome = Key(ui.KeyHome)
KeyInsert = Key(ui.KeyInsert) KeyInsert = Key(ui.KeyInsert)
KeyLeft = Key(ui.KeyLeft) KeyLeft = Key(ui.KeyLeft)
KeyLeftBracket = Key(ui.KeyLeftBracket)
KeyMinus = Key(ui.KeyMinus)
KeyPageDown = Key(ui.KeyPageDown) KeyPageDown = Key(ui.KeyPageDown)
KeyPageUp = Key(ui.KeyPageUp) KeyPageUp = Key(ui.KeyPageUp)
KeyPeriod = Key(ui.KeyPeriod) KeyPeriod = Key(ui.KeyPeriod)
KeyRight = Key(ui.KeyRight) KeyRight = Key(ui.KeyRight)
KeyRightBracket = Key(ui.KeyRightBracket)
KeySemicolon = Key(ui.KeySemicolon)
KeyShift = Key(ui.KeyShift) KeyShift = Key(ui.KeyShift)
KeySlash = Key(ui.KeySlash)
KeySpace = Key(ui.KeySpace) KeySpace = Key(ui.KeySpace)
KeyTab = Key(ui.KeyTab) KeyTab = Key(ui.KeyTab)
KeyUp = Key(ui.KeyUp) KeyUp = Key(ui.KeyUp)