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

@ -26,72 +26,81 @@ import (
) )
var glfwKeyCodeToKey = map[glfw.Key]Key{ var glfwKeyCodeToKey = map[glfw.Key]Key{
glfw.Key0: Key0, glfw.Key0: Key0,
glfw.Key1: Key1, glfw.Key1: Key1,
glfw.Key2: Key2, glfw.Key2: Key2,
glfw.Key3: Key3, glfw.Key3: Key3,
glfw.Key4: Key4, glfw.Key4: Key4,
glfw.Key5: Key5, glfw.Key5: Key5,
glfw.Key6: Key6, glfw.Key6: Key6,
glfw.Key7: Key7, glfw.Key7: Key7,
glfw.Key8: Key8, glfw.Key8: Key8,
glfw.Key9: Key9, glfw.Key9: Key9,
glfw.KeyA: KeyA, glfw.KeyA: KeyA,
glfw.KeyB: KeyB, glfw.KeyB: KeyB,
glfw.KeyC: KeyC, glfw.KeyC: KeyC,
glfw.KeyD: KeyD, glfw.KeyD: KeyD,
glfw.KeyE: KeyE, glfw.KeyE: KeyE,
glfw.KeyF: KeyF, glfw.KeyF: KeyF,
glfw.KeyG: KeyG, glfw.KeyG: KeyG,
glfw.KeyH: KeyH, glfw.KeyH: KeyH,
glfw.KeyI: KeyI, glfw.KeyI: KeyI,
glfw.KeyJ: KeyJ, glfw.KeyJ: KeyJ,
glfw.KeyK: KeyK, glfw.KeyK: KeyK,
glfw.KeyL: KeyL, glfw.KeyL: KeyL,
glfw.KeyM: KeyM, glfw.KeyM: KeyM,
glfw.KeyN: KeyN, glfw.KeyN: KeyN,
glfw.KeyO: KeyO, glfw.KeyO: KeyO,
glfw.KeyP: KeyP, glfw.KeyP: KeyP,
glfw.KeyQ: KeyQ, glfw.KeyQ: KeyQ,
glfw.KeyR: KeyR, glfw.KeyR: KeyR,
glfw.KeyS: KeyS, glfw.KeyS: KeyS,
glfw.KeyT: KeyT, glfw.KeyT: KeyT,
glfw.KeyU: KeyU, glfw.KeyU: KeyU,
glfw.KeyV: KeyV, glfw.KeyV: KeyV,
glfw.KeyW: KeyW, glfw.KeyW: KeyW,
glfw.KeyX: KeyX, glfw.KeyX: KeyX,
glfw.KeyY: KeyY, glfw.KeyY: KeyY,
glfw.KeyZ: KeyZ, glfw.KeyZ: KeyZ,
glfw.KeyBackspace: KeyBackspace, glfw.KeyApostrophe: KeyApostrophe,
glfw.KeyCapsLock: KeyCapsLock, glfw.KeyBackslash: KeyBackslash,
glfw.KeyComma: KeyComma, glfw.KeyBackspace: KeyBackspace,
glfw.KeyDelete: KeyDelete, glfw.KeyCapsLock: KeyCapsLock,
glfw.KeyDown: KeyDown, glfw.KeyComma: KeyComma,
glfw.KeyEnd: KeyEnd, glfw.KeyDelete: KeyDelete,
glfw.KeyEnter: KeyEnter, glfw.KeyDown: KeyDown,
glfw.KeyEscape: KeyEscape, glfw.KeyEnd: KeyEnd,
glfw.KeyF1: KeyF1, glfw.KeyEnter: KeyEnter,
glfw.KeyF2: KeyF2, glfw.KeyEqual: KeyEqual,
glfw.KeyF3: KeyF3, glfw.KeyEscape: KeyEscape,
glfw.KeyF4: KeyF4, glfw.KeyF1: KeyF1,
glfw.KeyF5: KeyF5, glfw.KeyF2: KeyF2,
glfw.KeyF6: KeyF6, glfw.KeyF3: KeyF3,
glfw.KeyF7: KeyF7, glfw.KeyF4: KeyF4,
glfw.KeyF8: KeyF8, glfw.KeyF5: KeyF5,
glfw.KeyF9: KeyF9, glfw.KeyF6: KeyF6,
glfw.KeyF10: KeyF10, glfw.KeyF7: KeyF7,
glfw.KeyF11: KeyF11, glfw.KeyF8: KeyF8,
glfw.KeyF12: KeyF12, glfw.KeyF9: KeyF9,
glfw.KeyHome: KeyHome, glfw.KeyF10: KeyF10,
glfw.KeyInsert: KeyInsert, glfw.KeyF11: KeyF11,
glfw.KeyLeft: KeyLeft, glfw.KeyF12: KeyF12,
glfw.KeyPageDown: KeyPageDown, glfw.KeyGraveAccent: KeyGraveAccent,
glfw.KeyPageUp: KeyPageUp, glfw.KeyHome: KeyHome,
glfw.KeyPeriod: KeyPeriod, glfw.KeyInsert: KeyInsert,
glfw.KeyRight: KeyRight, glfw.KeyLeft: KeyLeft,
glfw.KeySpace: KeySpace, glfw.KeyLeftBracket: KeyLeftBracket,
glfw.KeyTab: KeyTab, glfw.KeyMinus: KeyMinus,
glfw.KeyUp: KeyUp, glfw.KeyPageDown: KeyPageDown,
glfw.KeyPageUp: KeyPageUp,
glfw.KeyPeriod: KeyPeriod,
glfw.KeyRight: KeyRight,
glfw.KeyRightBracket: KeyRightBracket,
glfw.KeySemicolon: KeySemicolon,
glfw.KeySlash: KeySlash,
glfw.KeySpace: KeySpace,
glfw.KeyTab: KeyTab,
glfw.KeyUp: KeyUp,
glfw.KeyLeftAlt: KeyAlt, glfw.KeyLeftAlt: KeyAlt,
glfw.KeyRightAlt: KeyAlt, glfw.KeyRightAlt: KeyAlt,

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,
} }

149
keys.go
View File

@ -27,74 +27,83 @@ type Key int
// Keys // Keys
const ( const (
Key0 = Key(ui.Key0) Key0 = Key(ui.Key0)
Key1 = Key(ui.Key1) Key1 = Key(ui.Key1)
Key2 = Key(ui.Key2) Key2 = Key(ui.Key2)
Key3 = Key(ui.Key3) Key3 = Key(ui.Key3)
Key4 = Key(ui.Key4) Key4 = Key(ui.Key4)
Key5 = Key(ui.Key5) Key5 = Key(ui.Key5)
Key6 = Key(ui.Key6) Key6 = Key(ui.Key6)
Key7 = Key(ui.Key7) Key7 = Key(ui.Key7)
Key8 = Key(ui.Key8) Key8 = Key(ui.Key8)
Key9 = Key(ui.Key9) Key9 = Key(ui.Key9)
KeyA = Key(ui.KeyA) KeyA = Key(ui.KeyA)
KeyB = Key(ui.KeyB) KeyB = Key(ui.KeyB)
KeyC = Key(ui.KeyC) KeyC = Key(ui.KeyC)
KeyD = Key(ui.KeyD) KeyD = Key(ui.KeyD)
KeyE = Key(ui.KeyE) KeyE = Key(ui.KeyE)
KeyF = Key(ui.KeyF) KeyF = Key(ui.KeyF)
KeyG = Key(ui.KeyG) KeyG = Key(ui.KeyG)
KeyH = Key(ui.KeyH) KeyH = Key(ui.KeyH)
KeyI = Key(ui.KeyI) KeyI = Key(ui.KeyI)
KeyJ = Key(ui.KeyJ) KeyJ = Key(ui.KeyJ)
KeyK = Key(ui.KeyK) KeyK = Key(ui.KeyK)
KeyL = Key(ui.KeyL) KeyL = Key(ui.KeyL)
KeyM = Key(ui.KeyM) KeyM = Key(ui.KeyM)
KeyN = Key(ui.KeyN) KeyN = Key(ui.KeyN)
KeyO = Key(ui.KeyO) KeyO = Key(ui.KeyO)
KeyP = Key(ui.KeyP) KeyP = Key(ui.KeyP)
KeyQ = Key(ui.KeyQ) KeyQ = Key(ui.KeyQ)
KeyR = Key(ui.KeyR) KeyR = Key(ui.KeyR)
KeyS = Key(ui.KeyS) KeyS = Key(ui.KeyS)
KeyT = Key(ui.KeyT) KeyT = Key(ui.KeyT)
KeyU = Key(ui.KeyU) KeyU = Key(ui.KeyU)
KeyV = Key(ui.KeyV) KeyV = Key(ui.KeyV)
KeyW = Key(ui.KeyW) KeyW = Key(ui.KeyW)
KeyX = Key(ui.KeyX) KeyX = Key(ui.KeyX)
KeyY = Key(ui.KeyY) KeyY = Key(ui.KeyY)
KeyZ = Key(ui.KeyZ) KeyZ = Key(ui.KeyZ)
KeyAlt = Key(ui.KeyAlt) KeyAlt = Key(ui.KeyAlt)
KeyBackspace = Key(ui.KeyBackspace) KeyApostrophe = Key(ui.KeyApostrophe)
KeyCapsLock = Key(ui.KeyCapsLock) KeyBackslash = Key(ui.KeyBackslash)
KeyComma = Key(ui.KeyComma) KeyBackspace = Key(ui.KeyBackspace)
KeyControl = Key(ui.KeyControl) KeyCapsLock = Key(ui.KeyCapsLock)
KeyDelete = Key(ui.KeyDelete) KeyComma = Key(ui.KeyComma)
KeyDown = Key(ui.KeyDown) KeyControl = Key(ui.KeyControl)
KeyEnd = Key(ui.KeyEnd) KeyDelete = Key(ui.KeyDelete)
KeyEnter = Key(ui.KeyEnter) KeyDown = Key(ui.KeyDown)
KeyEscape = Key(ui.KeyEscape) KeyEnd = Key(ui.KeyEnd)
KeyF1 = Key(ui.KeyF1) KeyEnter = Key(ui.KeyEnter)
KeyF2 = Key(ui.KeyF2) KeyEqual = Key(ui.KeyEqual)
KeyF3 = Key(ui.KeyF3) KeyEscape = Key(ui.KeyEscape)
KeyF4 = Key(ui.KeyF4) KeyF1 = Key(ui.KeyF1)
KeyF5 = Key(ui.KeyF5) KeyF2 = Key(ui.KeyF2)
KeyF6 = Key(ui.KeyF6) KeyF3 = Key(ui.KeyF3)
KeyF7 = Key(ui.KeyF7) KeyF4 = Key(ui.KeyF4)
KeyF8 = Key(ui.KeyF8) KeyF5 = Key(ui.KeyF5)
KeyF9 = Key(ui.KeyF9) KeyF6 = Key(ui.KeyF6)
KeyF10 = Key(ui.KeyF10) KeyF7 = Key(ui.KeyF7)
KeyF11 = Key(ui.KeyF11) KeyF8 = Key(ui.KeyF8)
KeyF12 = Key(ui.KeyF12) KeyF9 = Key(ui.KeyF9)
KeyHome = Key(ui.KeyHome) KeyF10 = Key(ui.KeyF10)
KeyInsert = Key(ui.KeyInsert) KeyF11 = Key(ui.KeyF11)
KeyLeft = Key(ui.KeyLeft) KeyF12 = Key(ui.KeyF12)
KeyPageDown = Key(ui.KeyPageDown) KeyGraveAccent = Key(ui.KeyGraveAccent)
KeyPageUp = Key(ui.KeyPageUp) KeyHome = Key(ui.KeyHome)
KeyPeriod = Key(ui.KeyPeriod) KeyInsert = Key(ui.KeyInsert)
KeyRight = Key(ui.KeyRight) KeyLeft = Key(ui.KeyLeft)
KeyShift = Key(ui.KeyShift) KeyLeftBracket = Key(ui.KeyLeftBracket)
KeySpace = Key(ui.KeySpace) KeyMinus = Key(ui.KeyMinus)
KeyTab = Key(ui.KeyTab) KeyPageDown = Key(ui.KeyPageDown)
KeyUp = Key(ui.KeyUp) KeyPageUp = Key(ui.KeyPageUp)
KeyMax = KeyUp KeyPeriod = Key(ui.KeyPeriod)
KeyRight = Key(ui.KeyRight)
KeyRightBracket = Key(ui.KeyRightBracket)
KeySemicolon = Key(ui.KeySemicolon)
KeyShift = Key(ui.KeyShift)
KeySlash = Key(ui.KeySlash)
KeySpace = Key(ui.KeySpace)
KeyTab = Key(ui.KeyTab)
KeyUp = Key(ui.KeyUp)
KeyMax = KeyUp
) )