driver: Add (Key).String()

This commit is contained in:
Hajime Hoshi 2020-04-21 22:33:18 +09:00
parent a190569e23
commit ea99743e0d
2 changed files with 228 additions and 0 deletions

View File

@ -419,6 +419,10 @@ const driverKeysTmpl = `{{.License}}
package driver package driver
import (
"fmt"
)
type Key int type Key int
const ( const (
@ -427,6 +431,14 @@ const (
KeyReserved1 KeyReserved1
KeyReserved2 KeyReserved2
) )
func (k Key) String() string {
switch k {
{{range $index, $name := .DriverKeyNames}}case Key{{$name}}:
return {{$name | printf "Key%s" | printf "%q"}}
{{end}}}
panic(fmt.Sprintf("driver: invalid key: %v", k))
}
` `
const eventKeysTmpl = `{{.License}} const eventKeysTmpl = `{{.License}}

View File

@ -16,6 +16,10 @@
package driver package driver
import (
"fmt"
)
type Key int type Key int
const ( const (
@ -126,3 +130,215 @@ const (
KeyReserved1 KeyReserved1
KeyReserved2 KeyReserved2
) )
func (k Key) String() string {
switch k {
case Key0:
return "Key0"
case Key1:
return "Key1"
case Key2:
return "Key2"
case Key3:
return "Key3"
case Key4:
return "Key4"
case Key5:
return "Key5"
case Key6:
return "Key6"
case Key7:
return "Key7"
case Key8:
return "Key8"
case Key9:
return "Key9"
case KeyA:
return "KeyA"
case KeyB:
return "KeyB"
case KeyC:
return "KeyC"
case KeyD:
return "KeyD"
case KeyE:
return "KeyE"
case KeyF:
return "KeyF"
case KeyG:
return "KeyG"
case KeyH:
return "KeyH"
case KeyI:
return "KeyI"
case KeyJ:
return "KeyJ"
case KeyK:
return "KeyK"
case KeyL:
return "KeyL"
case KeyM:
return "KeyM"
case KeyN:
return "KeyN"
case KeyO:
return "KeyO"
case KeyP:
return "KeyP"
case KeyQ:
return "KeyQ"
case KeyR:
return "KeyR"
case KeyS:
return "KeyS"
case KeyT:
return "KeyT"
case KeyU:
return "KeyU"
case KeyV:
return "KeyV"
case KeyW:
return "KeyW"
case KeyX:
return "KeyX"
case KeyY:
return "KeyY"
case KeyZ:
return "KeyZ"
case KeyApostrophe:
return "KeyApostrophe"
case KeyBackslash:
return "KeyBackslash"
case KeyBackspace:
return "KeyBackspace"
case KeyCapsLock:
return "KeyCapsLock"
case KeyComma:
return "KeyComma"
case KeyDelete:
return "KeyDelete"
case KeyDown:
return "KeyDown"
case KeyEnd:
return "KeyEnd"
case KeyEnter:
return "KeyEnter"
case KeyEqual:
return "KeyEqual"
case KeyEscape:
return "KeyEscape"
case KeyF1:
return "KeyF1"
case KeyF2:
return "KeyF2"
case KeyF3:
return "KeyF3"
case KeyF4:
return "KeyF4"
case KeyF5:
return "KeyF5"
case KeyF6:
return "KeyF6"
case KeyF7:
return "KeyF7"
case KeyF8:
return "KeyF8"
case KeyF9:
return "KeyF9"
case KeyF10:
return "KeyF10"
case KeyF11:
return "KeyF11"
case KeyF12:
return "KeyF12"
case KeyGraveAccent:
return "KeyGraveAccent"
case KeyHome:
return "KeyHome"
case KeyInsert:
return "KeyInsert"
case KeyKP0:
return "KeyKP0"
case KeyKP1:
return "KeyKP1"
case KeyKP2:
return "KeyKP2"
case KeyKP3:
return "KeyKP3"
case KeyKP4:
return "KeyKP4"
case KeyKP5:
return "KeyKP5"
case KeyKP6:
return "KeyKP6"
case KeyKP7:
return "KeyKP7"
case KeyKP8:
return "KeyKP8"
case KeyKP9:
return "KeyKP9"
case KeyKPAdd:
return "KeyKPAdd"
case KeyKPDecimal:
return "KeyKPDecimal"
case KeyKPDivide:
return "KeyKPDivide"
case KeyKPEnter:
return "KeyKPEnter"
case KeyKPEqual:
return "KeyKPEqual"
case KeyKPMultiply:
return "KeyKPMultiply"
case KeyKPSubtract:
return "KeyKPSubtract"
case KeyLeft:
return "KeyLeft"
case KeyLeftAlt:
return "KeyLeftAlt"
case KeyLeftBracket:
return "KeyLeftBracket"
case KeyLeftControl:
return "KeyLeftControl"
case KeyLeftShift:
return "KeyLeftShift"
case KeyMenu:
return "KeyMenu"
case KeyMinus:
return "KeyMinus"
case KeyNumLock:
return "KeyNumLock"
case KeyPageDown:
return "KeyPageDown"
case KeyPageUp:
return "KeyPageUp"
case KeyPause:
return "KeyPause"
case KeyPeriod:
return "KeyPeriod"
case KeyPrintScreen:
return "KeyPrintScreen"
case KeyRight:
return "KeyRight"
case KeyRightAlt:
return "KeyRightAlt"
case KeyRightBracket:
return "KeyRightBracket"
case KeyRightControl:
return "KeyRightControl"
case KeyRightShift:
return "KeyRightShift"
case KeyScrollLock:
return "KeyScrollLock"
case KeySemicolon:
return "KeySemicolon"
case KeySlash:
return "KeySlash"
case KeySpace:
return "KeySpace"
case KeyTab:
return "KeyTab"
case KeyUp:
return "KeyUp"
}
panic(fmt.Sprintf("driver: invalid key: %v", k))
}