input: Add (Key).String()

This commit is contained in:
Hajime Hoshi 2018-04-14 03:20:43 +09:00
parent 61d4df0e04
commit 95c4ce0ddc
2 changed files with 212 additions and 0 deletions

View File

@ -183,6 +183,17 @@ const (
{{end}} KeyMax Key = Key{{.LastKeyName}}
)
// String returns a string representing the key.
//
// If k is an undefined key, String returns an empty string.
func (k Key) String() string {
switch k {
{{range $name := .KeyNames}}case Key{{$name}}:
return {{$name | printf "%q"}}
{{end}}}
return ""
}
func keyNameToKey(name string) (Key, bool) {
switch strings.ToLower(name) {
{{range $name := .KeyNames}}case {{$name | printf "%q" | ToLower}}:

201
keys.go
View File

@ -130,6 +130,207 @@ const (
KeyMax Key = KeyUp
)
// String returns a string representing the key.
//
// If k is an undefined key, String returns an empty string.
func (k Key) String() string {
switch k {
case Key0:
return "0"
case Key1:
return "1"
case Key2:
return "2"
case Key3:
return "3"
case Key4:
return "4"
case Key5:
return "5"
case Key6:
return "6"
case Key7:
return "7"
case Key8:
return "8"
case Key9:
return "9"
case KeyA:
return "A"
case KeyB:
return "B"
case KeyC:
return "C"
case KeyD:
return "D"
case KeyE:
return "E"
case KeyF:
return "F"
case KeyG:
return "G"
case KeyH:
return "H"
case KeyI:
return "I"
case KeyJ:
return "J"
case KeyK:
return "K"
case KeyL:
return "L"
case KeyM:
return "M"
case KeyN:
return "N"
case KeyO:
return "O"
case KeyP:
return "P"
case KeyQ:
return "Q"
case KeyR:
return "R"
case KeyS:
return "S"
case KeyT:
return "T"
case KeyU:
return "U"
case KeyV:
return "V"
case KeyW:
return "W"
case KeyX:
return "X"
case KeyY:
return "Y"
case KeyZ:
return "Z"
case KeyAlt:
return "Alt"
case KeyApostrophe:
return "Apostrophe"
case KeyBackslash:
return "Backslash"
case KeyBackspace:
return "Backspace"
case KeyCapsLock:
return "CapsLock"
case KeyComma:
return "Comma"
case KeyControl:
return "Control"
case KeyDelete:
return "Delete"
case KeyDown:
return "Down"
case KeyEnd:
return "End"
case KeyEnter:
return "Enter"
case KeyEqual:
return "Equal"
case KeyEscape:
return "Escape"
case KeyF1:
return "F1"
case KeyF2:
return "F2"
case KeyF3:
return "F3"
case KeyF4:
return "F4"
case KeyF5:
return "F5"
case KeyF6:
return "F6"
case KeyF7:
return "F7"
case KeyF8:
return "F8"
case KeyF9:
return "F9"
case KeyF10:
return "F10"
case KeyF11:
return "F11"
case KeyF12:
return "F12"
case KeyGraveAccent:
return "GraveAccent"
case KeyHome:
return "Home"
case KeyInsert:
return "Insert"
case KeyKP0:
return "KP0"
case KeyKP1:
return "KP1"
case KeyKP2:
return "KP2"
case KeyKP3:
return "KP3"
case KeyKP4:
return "KP4"
case KeyKP5:
return "KP5"
case KeyKP6:
return "KP6"
case KeyKP7:
return "KP7"
case KeyKP8:
return "KP8"
case KeyKP9:
return "KP9"
case KeyKPAdd:
return "KPAdd"
case KeyKPDecimal:
return "KPDecimal"
case KeyKPDivide:
return "KPDivide"
case KeyKPEnter:
return "KPEnter"
case KeyKPEqual:
return "KPEqual"
case KeyKPMultiply:
return "KPMultiply"
case KeyKPSubtract:
return "KPSubtract"
case KeyLeft:
return "Left"
case KeyLeftBracket:
return "LeftBracket"
case KeyMinus:
return "Minus"
case KeyNumLock:
return "NumLock"
case KeyPageDown:
return "PageDown"
case KeyPageUp:
return "PageUp"
case KeyPeriod:
return "Period"
case KeyRight:
return "Right"
case KeyRightBracket:
return "RightBracket"
case KeySemicolon:
return "Semicolon"
case KeyShift:
return "Shift"
case KeySlash:
return "Slash"
case KeySpace:
return "Space"
case KeyTab:
return "Tab"
case KeyUp:
return "Up"
}
return ""
}
func keyNameToKey(name string) (Key, bool) {
switch strings.ToLower(name) {
case "0":