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",
"Escape": "Escape",
"Backspace": "Backspace",
"Quote": "Apostrophe",
"Minus": "Minus",
"Slash": "Slash",
"Semicolon": "Semicolon",
"Equal": "Equal",
"BracketLeft": "LeftBracket",
"Backslash": "Backslash",
"BracketRight": "RightBracket",
"Backquote": "GraveAccent",
}
// ASCII: 0 - 9
for c := '0'; c <= '9'; c++ {
@ -79,8 +88,8 @@ func init() {
func init() {
keyCodeToNameSafari = map[int]string{
0xBC: "Comma",
0xBE: "Period",
0xbc: "Comma",
0xbe: "Period",
0x12: "Alt",
0x14: "CapsLock",
0x11: "Control",
@ -99,7 +108,15 @@ func init() {
0x27: "Right",
0x26: "Up",
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",
}
// ASCII: 0 - 9

View File

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

View File

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

View File

@ -25,7 +25,11 @@ var codeToKey = map[string]Key{
"ArrowLeft": KeyLeft,
"ArrowRight": KeyRight,
"ArrowUp": KeyUp,
"Backquote": KeyGraveAccent,
"Backslash": KeyBackslash,
"Backspace": KeyBackspace,
"BracketLeft": KeyLeftBracket,
"BracketRight": KeyRightBracket,
"CapsLock": KeyCapsLock,
"Comma": KeyComma,
"ControlLeft": KeyControl,
@ -43,6 +47,7 @@ var codeToKey = map[string]Key{
"Digit9": Key9,
"End": KeyEnd,
"Enter": KeyEnter,
"Equal": KeyEqual,
"Escape": KeyEscape,
"F1": KeyF1,
"F10": KeyF10,
@ -84,11 +89,15 @@ var codeToKey = map[string]Key{
"KeyX": KeyX,
"KeyY": KeyY,
"KeyZ": KeyZ,
"Minus": KeyMinus,
"PageDown": KeyPageDown,
"PageUp": KeyPageUp,
"Period": KeyPeriod,
"Quote": KeyApostrophe,
"Semicolon": KeySemicolon,
"ShiftLeft": KeyShift,
"ShiftRight": KeyShift,
"Slash": KeySlash,
"Space": KeySpace,
"Tab": KeyTab,
}
@ -161,6 +170,15 @@ var keyCodeToKeySafari = map[int]Key{
121: KeyF10,
122: KeyF11,
123: KeyF12,
186: KeySemicolon,
187: KeyEqual,
188: KeyComma,
189: KeyMinus,
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
const (
Key0 = Key(ui.Key0)
Key1 = Key(ui.Key1)
Key2 = Key(ui.Key2)
Key3 = Key(ui.Key3)
Key4 = Key(ui.Key4)
Key5 = Key(ui.Key5)
Key6 = Key(ui.Key6)
Key7 = Key(ui.Key7)
Key8 = Key(ui.Key8)
Key9 = Key(ui.Key9)
KeyA = Key(ui.KeyA)
KeyB = Key(ui.KeyB)
KeyC = Key(ui.KeyC)
KeyD = Key(ui.KeyD)
KeyE = Key(ui.KeyE)
KeyF = Key(ui.KeyF)
KeyG = Key(ui.KeyG)
KeyH = Key(ui.KeyH)
KeyI = Key(ui.KeyI)
KeyJ = Key(ui.KeyJ)
KeyK = Key(ui.KeyK)
KeyL = Key(ui.KeyL)
KeyM = Key(ui.KeyM)
KeyN = Key(ui.KeyN)
KeyO = Key(ui.KeyO)
KeyP = Key(ui.KeyP)
KeyQ = Key(ui.KeyQ)
KeyR = Key(ui.KeyR)
KeyS = Key(ui.KeyS)
KeyT = Key(ui.KeyT)
KeyU = Key(ui.KeyU)
KeyV = Key(ui.KeyV)
KeyW = Key(ui.KeyW)
KeyX = Key(ui.KeyX)
KeyY = Key(ui.KeyY)
KeyZ = Key(ui.KeyZ)
KeyAlt = Key(ui.KeyAlt)
KeyBackspace = Key(ui.KeyBackspace)
KeyCapsLock = Key(ui.KeyCapsLock)
KeyComma = Key(ui.KeyComma)
KeyControl = Key(ui.KeyControl)
KeyDelete = Key(ui.KeyDelete)
KeyDown = Key(ui.KeyDown)
KeyEnd = Key(ui.KeyEnd)
KeyEnter = Key(ui.KeyEnter)
KeyEscape = Key(ui.KeyEscape)
KeyF1 = Key(ui.KeyF1)
KeyF2 = Key(ui.KeyF2)
KeyF3 = Key(ui.KeyF3)
KeyF4 = Key(ui.KeyF4)
KeyF5 = Key(ui.KeyF5)
KeyF6 = Key(ui.KeyF6)
KeyF7 = Key(ui.KeyF7)
KeyF8 = Key(ui.KeyF8)
KeyF9 = Key(ui.KeyF9)
KeyF10 = Key(ui.KeyF10)
KeyF11 = Key(ui.KeyF11)
KeyF12 = Key(ui.KeyF12)
KeyHome = Key(ui.KeyHome)
KeyInsert = Key(ui.KeyInsert)
KeyLeft = Key(ui.KeyLeft)
KeyPageDown = Key(ui.KeyPageDown)
KeyPageUp = Key(ui.KeyPageUp)
KeyPeriod = Key(ui.KeyPeriod)
KeyRight = Key(ui.KeyRight)
KeyShift = Key(ui.KeyShift)
KeySpace = Key(ui.KeySpace)
KeyTab = Key(ui.KeyTab)
KeyUp = Key(ui.KeyUp)
KeyMax = KeyUp
Key0 = Key(ui.Key0)
Key1 = Key(ui.Key1)
Key2 = Key(ui.Key2)
Key3 = Key(ui.Key3)
Key4 = Key(ui.Key4)
Key5 = Key(ui.Key5)
Key6 = Key(ui.Key6)
Key7 = Key(ui.Key7)
Key8 = Key(ui.Key8)
Key9 = Key(ui.Key9)
KeyA = Key(ui.KeyA)
KeyB = Key(ui.KeyB)
KeyC = Key(ui.KeyC)
KeyD = Key(ui.KeyD)
KeyE = Key(ui.KeyE)
KeyF = Key(ui.KeyF)
KeyG = Key(ui.KeyG)
KeyH = Key(ui.KeyH)
KeyI = Key(ui.KeyI)
KeyJ = Key(ui.KeyJ)
KeyK = Key(ui.KeyK)
KeyL = Key(ui.KeyL)
KeyM = Key(ui.KeyM)
KeyN = Key(ui.KeyN)
KeyO = Key(ui.KeyO)
KeyP = Key(ui.KeyP)
KeyQ = Key(ui.KeyQ)
KeyR = Key(ui.KeyR)
KeyS = Key(ui.KeyS)
KeyT = Key(ui.KeyT)
KeyU = Key(ui.KeyU)
KeyV = Key(ui.KeyV)
KeyW = Key(ui.KeyW)
KeyX = Key(ui.KeyX)
KeyY = Key(ui.KeyY)
KeyZ = Key(ui.KeyZ)
KeyAlt = Key(ui.KeyAlt)
KeyApostrophe = Key(ui.KeyApostrophe)
KeyBackslash = Key(ui.KeyBackslash)
KeyBackspace = Key(ui.KeyBackspace)
KeyCapsLock = Key(ui.KeyCapsLock)
KeyComma = Key(ui.KeyComma)
KeyControl = Key(ui.KeyControl)
KeyDelete = Key(ui.KeyDelete)
KeyDown = Key(ui.KeyDown)
KeyEnd = Key(ui.KeyEnd)
KeyEnter = Key(ui.KeyEnter)
KeyEqual = Key(ui.KeyEqual)
KeyEscape = Key(ui.KeyEscape)
KeyF1 = Key(ui.KeyF1)
KeyF2 = Key(ui.KeyF2)
KeyF3 = Key(ui.KeyF3)
KeyF4 = Key(ui.KeyF4)
KeyF5 = Key(ui.KeyF5)
KeyF6 = Key(ui.KeyF6)
KeyF7 = Key(ui.KeyF7)
KeyF8 = Key(ui.KeyF8)
KeyF9 = Key(ui.KeyF9)
KeyF10 = Key(ui.KeyF10)
KeyF11 = Key(ui.KeyF11)
KeyF12 = Key(ui.KeyF12)
KeyGraveAccent = Key(ui.KeyGraveAccent)
KeyHome = Key(ui.KeyHome)
KeyInsert = Key(ui.KeyInsert)
KeyLeft = Key(ui.KeyLeft)
KeyLeftBracket = Key(ui.KeyLeftBracket)
KeyMinus = Key(ui.KeyMinus)
KeyPageDown = Key(ui.KeyPageDown)
KeyPageUp = Key(ui.KeyPageUp)
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
)