mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
input: driver.Key now distinguishes left/right modifier keys
This is a preparation for event package, that will have key enum. Updates #926
This commit is contained in:
parent
23002c7597
commit
83b2d4b112
@ -46,7 +46,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
pressed := []ebiten.Key{}
|
var pressed []ebiten.Key
|
||||||
for k := ebiten.Key(0); k <= ebiten.KeyMax; k++ {
|
for k := ebiten.Key(0); k <= ebiten.KeyMax; k++ {
|
||||||
if ebiten.IsKeyPressed(k) {
|
if ebiten.IsKeyPressed(k) {
|
||||||
pressed = append(pressed, k)
|
pressed = append(pressed, k)
|
||||||
|
71
genkeys.go
71
genkeys.go
@ -88,10 +88,13 @@ func init() {
|
|||||||
nameToJSKeyCodes = map[string][]string{
|
nameToJSKeyCodes = map[string][]string{
|
||||||
"Comma": {"Comma"},
|
"Comma": {"Comma"},
|
||||||
"Period": {"Period"},
|
"Period": {"Period"},
|
||||||
"Alt": {"AltLeft", "AltRight"},
|
"LeftAlt": {"AltLeft"},
|
||||||
|
"RightAlt": {"AltRight"},
|
||||||
"CapsLock": {"CapsLock"},
|
"CapsLock": {"CapsLock"},
|
||||||
"Control": {"ControlLeft", "ControlRight"},
|
"LeftControl": {"ControlLeft"},
|
||||||
"Shift": {"ShiftLeft", "ShiftRight"},
|
"RightControl": {"ControlRight"},
|
||||||
|
"LeftShift": {"ShiftLeft"},
|
||||||
|
"RightShift": {"ShiftRight"},
|
||||||
"Enter": {"Enter"},
|
"Enter": {"Enter"},
|
||||||
"Space": {"Space"},
|
"Space": {"Space"},
|
||||||
"Tab": {"Tab"},
|
"Tab": {"Tab"},
|
||||||
@ -164,13 +167,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
// TODO: How should we treat modifier keys? Now 'left' modifier keys are available.
|
||||||
keyCodeToNameEdge = map[int]string{
|
keyCodeToNameEdge = map[int]string{
|
||||||
0xbc: "Comma",
|
0xbc: "Comma",
|
||||||
0xbe: "Period",
|
0xbe: "Period",
|
||||||
0x12: "Alt",
|
0x12: "LeftAlt",
|
||||||
0x14: "CapsLock",
|
0x14: "CapsLock",
|
||||||
0x11: "Control",
|
0x11: "LeftControl",
|
||||||
0x10: "Shift",
|
0x10: "LeftShift",
|
||||||
0x0D: "Enter",
|
0x0D: "Enter",
|
||||||
0x20: "Space",
|
0x20: "Space",
|
||||||
0x09: "Tab",
|
0x09: "Tab",
|
||||||
@ -249,10 +253,23 @@ type Key int
|
|||||||
|
|
||||||
// Keys.
|
// Keys.
|
||||||
const (
|
const (
|
||||||
{{range $index, $name := .EbitenKeyNames}}Key{{$name}} Key = Key(driver.Key{{$name}})
|
{{range $index, $name := .EbitenKeyNamesWithoutMods}}Key{{$name}} Key = Key(driver.Key{{$name}})
|
||||||
{{end}} KeyMax Key = Key{{.LastEbitenKeyName}}
|
{{end}} KeyAlt Key = Key(driver.KeyReserved0)
|
||||||
|
KeyControl Key = Key(driver.KeyReserved1)
|
||||||
|
KeyShift Key = Key(driver.KeyReserved2)
|
||||||
|
KeyMax Key = KeyShift
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (k Key) isValid() bool {
|
||||||
|
switch k {
|
||||||
|
{{range $name := .EbitenKeyNames}}case Key{{$name}}:
|
||||||
|
return true
|
||||||
|
{{end}}
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// String returns a string representing the key.
|
// String returns a string representing the key.
|
||||||
//
|
//
|
||||||
// If k is an undefined key, String returns an empty string.
|
// If k is an undefined key, String returns an empty string.
|
||||||
@ -282,8 +299,10 @@ package driver
|
|||||||
type Key int
|
type Key int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
{{range $index, $name := .EbitenKeyNames}}Key{{$name}}{{if eq $index 0}} Key = iota{{end}}
|
{{range $index, $name := .DriverKeyNames}}Key{{$name}}{{if eq $index 0}} Key = iota{{end}}
|
||||||
{{end}}
|
{{end}} KeyReserved0
|
||||||
|
KeyReserved1
|
||||||
|
KeyReserved2
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -301,14 +320,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var glfwKeyCodeToKey = map[glfw.Key]driver.Key{
|
var glfwKeyCodeToKey = map[glfw.Key]driver.Key{
|
||||||
{{range $index, $name := .EbitenKeyNamesWithoutMods}}glfw.Key{{$name}}: driver.Key{{$name}},
|
{{range $index, $name := .DriverKeyNames}}glfw.Key{{$name}}: driver.Key{{$name}},
|
||||||
{{end}}
|
{{end}}
|
||||||
glfw.KeyLeftAlt: driver.KeyAlt,
|
|
||||||
glfw.KeyRightAlt: driver.KeyAlt,
|
|
||||||
glfw.KeyLeftControl: driver.KeyControl,
|
|
||||||
glfw.KeyRightControl: driver.KeyControl,
|
|
||||||
glfw.KeyLeftShift: driver.KeyShift,
|
|
||||||
glfw.KeyRightShift: driver.KeyShift,
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -442,15 +455,31 @@ func main() {
|
|||||||
|
|
||||||
ebitenKeyNames := []string{}
|
ebitenKeyNames := []string{}
|
||||||
ebitenKeyNamesWithoutMods := []string{}
|
ebitenKeyNamesWithoutMods := []string{}
|
||||||
|
driverKeyNames := []string{}
|
||||||
for name := range nameToJSKeyCodes {
|
for name := range nameToJSKeyCodes {
|
||||||
ebitenKeyNames = append(ebitenKeyNames, name)
|
driverKeyNames = append(driverKeyNames, name)
|
||||||
if name != "Alt" && name != "Control" && name != "Shift" {
|
if !strings.HasSuffix(name, "Alt") && !strings.HasSuffix(name, "Control") && !strings.HasSuffix(name, "Shift") {
|
||||||
|
ebitenKeyNames = append(ebitenKeyNames, name)
|
||||||
ebitenKeyNamesWithoutMods = append(ebitenKeyNamesWithoutMods, name)
|
ebitenKeyNamesWithoutMods = append(ebitenKeyNamesWithoutMods, name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == "LeftAlt" {
|
||||||
|
ebitenKeyNames = append(ebitenKeyNames, "Alt")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == "LeftControl" {
|
||||||
|
ebitenKeyNames = append(ebitenKeyNames, "Control")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if name == "LeftShift" {
|
||||||
|
ebitenKeyNames = append(ebitenKeyNames, "Shift")
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(ebitenKeyNames, keyNamesLess(ebitenKeyNames))
|
sort.Slice(ebitenKeyNames, keyNamesLess(ebitenKeyNames))
|
||||||
sort.Slice(ebitenKeyNamesWithoutMods, keyNamesLess(ebitenKeyNamesWithoutMods))
|
sort.Slice(ebitenKeyNamesWithoutMods, keyNamesLess(ebitenKeyNamesWithoutMods))
|
||||||
|
sort.Slice(driverKeyNames, keyNamesLess(driverKeyNames))
|
||||||
|
|
||||||
for path, tmpl := range map[string]string{
|
for path, tmpl := range map[string]string{
|
||||||
"keys.go": ebitenKeysTmpl,
|
"keys.go": ebitenKeysTmpl,
|
||||||
@ -494,7 +523,7 @@ func main() {
|
|||||||
KeyCodeToNameEdge map[int]string
|
KeyCodeToNameEdge map[int]string
|
||||||
EbitenKeyNames []string
|
EbitenKeyNames []string
|
||||||
EbitenKeyNamesWithoutMods []string
|
EbitenKeyNamesWithoutMods []string
|
||||||
LastEbitenKeyName string
|
DriverKeyNames []string
|
||||||
NameToGLFWKeys map[string]glfw.Key
|
NameToGLFWKeys map[string]glfw.Key
|
||||||
}{
|
}{
|
||||||
License: license,
|
License: license,
|
||||||
@ -504,7 +533,7 @@ func main() {
|
|||||||
KeyCodeToNameEdge: keyCodeToNameEdge,
|
KeyCodeToNameEdge: keyCodeToNameEdge,
|
||||||
EbitenKeyNames: ebitenKeyNames,
|
EbitenKeyNames: ebitenKeyNames,
|
||||||
EbitenKeyNamesWithoutMods: ebitenKeyNamesWithoutMods,
|
EbitenKeyNamesWithoutMods: ebitenKeyNamesWithoutMods,
|
||||||
LastEbitenKeyName: ebitenKeyNames[len(ebitenKeyNames)-1],
|
DriverKeyNames: driverKeyNames,
|
||||||
NameToGLFWKeys: nameToGLFWKeys,
|
NameToGLFWKeys: nameToGLFWKeys,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
24
input.go
24
input.go
@ -42,7 +42,29 @@ func InputChars() []rune {
|
|||||||
//
|
//
|
||||||
// IsKeyPressed is concurrent-safe.
|
// IsKeyPressed is concurrent-safe.
|
||||||
func IsKeyPressed(key Key) bool {
|
func IsKeyPressed(key Key) bool {
|
||||||
return uidriver.Get().Input().IsKeyPressed(driver.Key(key))
|
// There are keys that are invalid values as ebiten.Key (e.g., driver.KeyLeftAlt).
|
||||||
|
// Skip such values.
|
||||||
|
if !key.isValid() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var keys []driver.Key
|
||||||
|
switch key {
|
||||||
|
case KeyAlt:
|
||||||
|
keys = append(keys, driver.KeyLeftAlt, driver.KeyRightAlt)
|
||||||
|
case KeyControl:
|
||||||
|
keys = append(keys, driver.KeyLeftControl, driver.KeyRightControl)
|
||||||
|
case KeyShift:
|
||||||
|
keys = append(keys, driver.KeyLeftShift, driver.KeyRightShift)
|
||||||
|
default:
|
||||||
|
keys = append(keys, driver.Key(key))
|
||||||
|
}
|
||||||
|
for _, k := range keys {
|
||||||
|
if uidriver.Get().Input().IsKeyPressed(k) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorPosition returns a position of a mouse cursor relative to the game screen (window). The cursor position is
|
// CursorPosition returns a position of a mouse cursor relative to the game screen (window). The cursor position is
|
||||||
|
@ -55,13 +55,11 @@ const (
|
|||||||
KeyX
|
KeyX
|
||||||
KeyY
|
KeyY
|
||||||
KeyZ
|
KeyZ
|
||||||
KeyAlt
|
|
||||||
KeyApostrophe
|
KeyApostrophe
|
||||||
KeyBackslash
|
KeyBackslash
|
||||||
KeyBackspace
|
KeyBackspace
|
||||||
KeyCapsLock
|
KeyCapsLock
|
||||||
KeyComma
|
KeyComma
|
||||||
KeyControl
|
|
||||||
KeyDelete
|
KeyDelete
|
||||||
KeyDown
|
KeyDown
|
||||||
KeyEnd
|
KeyEnd
|
||||||
@ -101,7 +99,10 @@ const (
|
|||||||
KeyKPMultiply
|
KeyKPMultiply
|
||||||
KeyKPSubtract
|
KeyKPSubtract
|
||||||
KeyLeft
|
KeyLeft
|
||||||
|
KeyLeftAlt
|
||||||
KeyLeftBracket
|
KeyLeftBracket
|
||||||
|
KeyLeftControl
|
||||||
|
KeyLeftShift
|
||||||
KeyMenu
|
KeyMenu
|
||||||
KeyMinus
|
KeyMinus
|
||||||
KeyNumLock
|
KeyNumLock
|
||||||
@ -111,12 +112,17 @@ const (
|
|||||||
KeyPeriod
|
KeyPeriod
|
||||||
KeyPrintScreen
|
KeyPrintScreen
|
||||||
KeyRight
|
KeyRight
|
||||||
|
KeyRightAlt
|
||||||
KeyRightBracket
|
KeyRightBracket
|
||||||
|
KeyRightControl
|
||||||
|
KeyRightShift
|
||||||
KeyScrollLock
|
KeyScrollLock
|
||||||
KeySemicolon
|
KeySemicolon
|
||||||
KeyShift
|
|
||||||
KeySlash
|
KeySlash
|
||||||
KeySpace
|
KeySpace
|
||||||
KeyTab
|
KeyTab
|
||||||
KeyUp
|
KeyUp
|
||||||
|
KeyReserved0
|
||||||
|
KeyReserved1
|
||||||
|
KeyReserved2
|
||||||
)
|
)
|
||||||
|
@ -107,7 +107,10 @@ var glfwKeyCodeToKey = map[glfw.Key]driver.Key{
|
|||||||
glfw.KeyKPMultiply: driver.KeyKPMultiply,
|
glfw.KeyKPMultiply: driver.KeyKPMultiply,
|
||||||
glfw.KeyKPSubtract: driver.KeyKPSubtract,
|
glfw.KeyKPSubtract: driver.KeyKPSubtract,
|
||||||
glfw.KeyLeft: driver.KeyLeft,
|
glfw.KeyLeft: driver.KeyLeft,
|
||||||
|
glfw.KeyLeftAlt: driver.KeyLeftAlt,
|
||||||
glfw.KeyLeftBracket: driver.KeyLeftBracket,
|
glfw.KeyLeftBracket: driver.KeyLeftBracket,
|
||||||
|
glfw.KeyLeftControl: driver.KeyLeftControl,
|
||||||
|
glfw.KeyLeftShift: driver.KeyLeftShift,
|
||||||
glfw.KeyMenu: driver.KeyMenu,
|
glfw.KeyMenu: driver.KeyMenu,
|
||||||
glfw.KeyMinus: driver.KeyMinus,
|
glfw.KeyMinus: driver.KeyMinus,
|
||||||
glfw.KeyNumLock: driver.KeyNumLock,
|
glfw.KeyNumLock: driver.KeyNumLock,
|
||||||
@ -117,18 +120,14 @@ var glfwKeyCodeToKey = map[glfw.Key]driver.Key{
|
|||||||
glfw.KeyPeriod: driver.KeyPeriod,
|
glfw.KeyPeriod: driver.KeyPeriod,
|
||||||
glfw.KeyPrintScreen: driver.KeyPrintScreen,
|
glfw.KeyPrintScreen: driver.KeyPrintScreen,
|
||||||
glfw.KeyRight: driver.KeyRight,
|
glfw.KeyRight: driver.KeyRight,
|
||||||
|
glfw.KeyRightAlt: driver.KeyRightAlt,
|
||||||
glfw.KeyRightBracket: driver.KeyRightBracket,
|
glfw.KeyRightBracket: driver.KeyRightBracket,
|
||||||
|
glfw.KeyRightControl: driver.KeyRightControl,
|
||||||
|
glfw.KeyRightShift: driver.KeyRightShift,
|
||||||
glfw.KeyScrollLock: driver.KeyScrollLock,
|
glfw.KeyScrollLock: driver.KeyScrollLock,
|
||||||
glfw.KeySemicolon: driver.KeySemicolon,
|
glfw.KeySemicolon: driver.KeySemicolon,
|
||||||
glfw.KeySlash: driver.KeySlash,
|
glfw.KeySlash: driver.KeySlash,
|
||||||
glfw.KeySpace: driver.KeySpace,
|
glfw.KeySpace: driver.KeySpace,
|
||||||
glfw.KeyTab: driver.KeyTab,
|
glfw.KeyTab: driver.KeyTab,
|
||||||
glfw.KeyUp: driver.KeyUp,
|
glfw.KeyUp: driver.KeyUp,
|
||||||
|
|
||||||
glfw.KeyLeftAlt: driver.KeyAlt,
|
|
||||||
glfw.KeyRightAlt: driver.KeyAlt,
|
|
||||||
glfw.KeyLeftControl: driver.KeyControl,
|
|
||||||
glfw.KeyRightControl: driver.KeyControl,
|
|
||||||
glfw.KeyLeftShift: driver.KeyShift,
|
|
||||||
glfw.KeyRightShift: driver.KeyShift,
|
|
||||||
}
|
}
|
||||||
|
@ -56,9 +56,6 @@ var keyToCodes = map[driver.Key][]string{
|
|||||||
driver.KeyA: {
|
driver.KeyA: {
|
||||||
"KeyA",
|
"KeyA",
|
||||||
},
|
},
|
||||||
driver.KeyAlt: {
|
|
||||||
"AltLeft", "AltRight",
|
|
||||||
},
|
|
||||||
driver.KeyApostrophe: {
|
driver.KeyApostrophe: {
|
||||||
"Quote",
|
"Quote",
|
||||||
},
|
},
|
||||||
@ -80,9 +77,6 @@ var keyToCodes = map[driver.Key][]string{
|
|||||||
driver.KeyComma: {
|
driver.KeyComma: {
|
||||||
"Comma",
|
"Comma",
|
||||||
},
|
},
|
||||||
driver.KeyControl: {
|
|
||||||
"ControlLeft", "ControlRight",
|
|
||||||
},
|
|
||||||
driver.KeyD: {
|
driver.KeyD: {
|
||||||
"KeyD",
|
"KeyD",
|
||||||
},
|
},
|
||||||
@ -227,9 +221,18 @@ var keyToCodes = map[driver.Key][]string{
|
|||||||
driver.KeyLeft: {
|
driver.KeyLeft: {
|
||||||
"ArrowLeft",
|
"ArrowLeft",
|
||||||
},
|
},
|
||||||
|
driver.KeyLeftAlt: {
|
||||||
|
"AltLeft",
|
||||||
|
},
|
||||||
driver.KeyLeftBracket: {
|
driver.KeyLeftBracket: {
|
||||||
"BracketLeft",
|
"BracketLeft",
|
||||||
},
|
},
|
||||||
|
driver.KeyLeftControl: {
|
||||||
|
"ControlLeft",
|
||||||
|
},
|
||||||
|
driver.KeyLeftShift: {
|
||||||
|
"ShiftLeft",
|
||||||
|
},
|
||||||
driver.KeyM: {
|
driver.KeyM: {
|
||||||
"KeyM",
|
"KeyM",
|
||||||
},
|
},
|
||||||
@ -275,9 +278,18 @@ var keyToCodes = map[driver.Key][]string{
|
|||||||
driver.KeyRight: {
|
driver.KeyRight: {
|
||||||
"ArrowRight",
|
"ArrowRight",
|
||||||
},
|
},
|
||||||
|
driver.KeyRightAlt: {
|
||||||
|
"AltRight",
|
||||||
|
},
|
||||||
driver.KeyRightBracket: {
|
driver.KeyRightBracket: {
|
||||||
"BracketRight",
|
"BracketRight",
|
||||||
},
|
},
|
||||||
|
driver.KeyRightControl: {
|
||||||
|
"ControlRight",
|
||||||
|
},
|
||||||
|
driver.KeyRightShift: {
|
||||||
|
"ShiftRight",
|
||||||
|
},
|
||||||
driver.KeyS: {
|
driver.KeyS: {
|
||||||
"KeyS",
|
"KeyS",
|
||||||
},
|
},
|
||||||
@ -287,9 +299,6 @@ var keyToCodes = map[driver.Key][]string{
|
|||||||
driver.KeySemicolon: {
|
driver.KeySemicolon: {
|
||||||
"Semicolon",
|
"Semicolon",
|
||||||
},
|
},
|
||||||
driver.KeyShift: {
|
|
||||||
"ShiftLeft", "ShiftRight",
|
|
||||||
},
|
|
||||||
driver.KeySlash: {
|
driver.KeySlash: {
|
||||||
"Slash",
|
"Slash",
|
||||||
},
|
},
|
||||||
@ -329,9 +338,9 @@ var keyCodeToKeyEdge = map[int]driver.Key{
|
|||||||
8: driver.KeyBackspace,
|
8: driver.KeyBackspace,
|
||||||
9: driver.KeyTab,
|
9: driver.KeyTab,
|
||||||
13: driver.KeyEnter,
|
13: driver.KeyEnter,
|
||||||
16: driver.KeyShift,
|
16: driver.KeyLeftShift,
|
||||||
17: driver.KeyControl,
|
17: driver.KeyLeftControl,
|
||||||
18: driver.KeyAlt,
|
18: driver.KeyLeftAlt,
|
||||||
19: driver.KeyPause,
|
19: driver.KeyPause,
|
||||||
20: driver.KeyCapsLock,
|
20: driver.KeyCapsLock,
|
||||||
27: driver.KeyEscape,
|
27: driver.KeyEscape,
|
||||||
|
216
keys.go
216
keys.go
@ -65,13 +65,11 @@ const (
|
|||||||
KeyX Key = Key(driver.KeyX)
|
KeyX Key = Key(driver.KeyX)
|
||||||
KeyY Key = Key(driver.KeyY)
|
KeyY Key = Key(driver.KeyY)
|
||||||
KeyZ Key = Key(driver.KeyZ)
|
KeyZ Key = Key(driver.KeyZ)
|
||||||
KeyAlt Key = Key(driver.KeyAlt)
|
|
||||||
KeyApostrophe Key = Key(driver.KeyApostrophe)
|
KeyApostrophe Key = Key(driver.KeyApostrophe)
|
||||||
KeyBackslash Key = Key(driver.KeyBackslash)
|
KeyBackslash Key = Key(driver.KeyBackslash)
|
||||||
KeyBackspace Key = Key(driver.KeyBackspace)
|
KeyBackspace Key = Key(driver.KeyBackspace)
|
||||||
KeyCapsLock Key = Key(driver.KeyCapsLock)
|
KeyCapsLock Key = Key(driver.KeyCapsLock)
|
||||||
KeyComma Key = Key(driver.KeyComma)
|
KeyComma Key = Key(driver.KeyComma)
|
||||||
KeyControl Key = Key(driver.KeyControl)
|
|
||||||
KeyDelete Key = Key(driver.KeyDelete)
|
KeyDelete Key = Key(driver.KeyDelete)
|
||||||
KeyDown Key = Key(driver.KeyDown)
|
KeyDown Key = Key(driver.KeyDown)
|
||||||
KeyEnd Key = Key(driver.KeyEnd)
|
KeyEnd Key = Key(driver.KeyEnd)
|
||||||
@ -124,14 +122,224 @@ const (
|
|||||||
KeyRightBracket Key = Key(driver.KeyRightBracket)
|
KeyRightBracket Key = Key(driver.KeyRightBracket)
|
||||||
KeyScrollLock Key = Key(driver.KeyScrollLock)
|
KeyScrollLock Key = Key(driver.KeyScrollLock)
|
||||||
KeySemicolon Key = Key(driver.KeySemicolon)
|
KeySemicolon Key = Key(driver.KeySemicolon)
|
||||||
KeyShift Key = Key(driver.KeyShift)
|
|
||||||
KeySlash Key = Key(driver.KeySlash)
|
KeySlash Key = Key(driver.KeySlash)
|
||||||
KeySpace Key = Key(driver.KeySpace)
|
KeySpace Key = Key(driver.KeySpace)
|
||||||
KeyTab Key = Key(driver.KeyTab)
|
KeyTab Key = Key(driver.KeyTab)
|
||||||
KeyUp Key = Key(driver.KeyUp)
|
KeyUp Key = Key(driver.KeyUp)
|
||||||
KeyMax Key = KeyUp
|
KeyAlt Key = Key(driver.KeyReserved0)
|
||||||
|
KeyControl Key = Key(driver.KeyReserved1)
|
||||||
|
KeyShift Key = Key(driver.KeyReserved2)
|
||||||
|
KeyMax Key = KeyShift
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (k Key) isValid() bool {
|
||||||
|
switch k {
|
||||||
|
case Key0:
|
||||||
|
return true
|
||||||
|
case Key1:
|
||||||
|
return true
|
||||||
|
case Key2:
|
||||||
|
return true
|
||||||
|
case Key3:
|
||||||
|
return true
|
||||||
|
case Key4:
|
||||||
|
return true
|
||||||
|
case Key5:
|
||||||
|
return true
|
||||||
|
case Key6:
|
||||||
|
return true
|
||||||
|
case Key7:
|
||||||
|
return true
|
||||||
|
case Key8:
|
||||||
|
return true
|
||||||
|
case Key9:
|
||||||
|
return true
|
||||||
|
case KeyA:
|
||||||
|
return true
|
||||||
|
case KeyB:
|
||||||
|
return true
|
||||||
|
case KeyC:
|
||||||
|
return true
|
||||||
|
case KeyD:
|
||||||
|
return true
|
||||||
|
case KeyE:
|
||||||
|
return true
|
||||||
|
case KeyF:
|
||||||
|
return true
|
||||||
|
case KeyG:
|
||||||
|
return true
|
||||||
|
case KeyH:
|
||||||
|
return true
|
||||||
|
case KeyI:
|
||||||
|
return true
|
||||||
|
case KeyJ:
|
||||||
|
return true
|
||||||
|
case KeyK:
|
||||||
|
return true
|
||||||
|
case KeyL:
|
||||||
|
return true
|
||||||
|
case KeyM:
|
||||||
|
return true
|
||||||
|
case KeyN:
|
||||||
|
return true
|
||||||
|
case KeyO:
|
||||||
|
return true
|
||||||
|
case KeyP:
|
||||||
|
return true
|
||||||
|
case KeyQ:
|
||||||
|
return true
|
||||||
|
case KeyR:
|
||||||
|
return true
|
||||||
|
case KeyS:
|
||||||
|
return true
|
||||||
|
case KeyT:
|
||||||
|
return true
|
||||||
|
case KeyU:
|
||||||
|
return true
|
||||||
|
case KeyV:
|
||||||
|
return true
|
||||||
|
case KeyW:
|
||||||
|
return true
|
||||||
|
case KeyX:
|
||||||
|
return true
|
||||||
|
case KeyY:
|
||||||
|
return true
|
||||||
|
case KeyZ:
|
||||||
|
return true
|
||||||
|
case KeyAlt:
|
||||||
|
return true
|
||||||
|
case KeyApostrophe:
|
||||||
|
return true
|
||||||
|
case KeyBackslash:
|
||||||
|
return true
|
||||||
|
case KeyBackspace:
|
||||||
|
return true
|
||||||
|
case KeyCapsLock:
|
||||||
|
return true
|
||||||
|
case KeyComma:
|
||||||
|
return true
|
||||||
|
case KeyControl:
|
||||||
|
return true
|
||||||
|
case KeyDelete:
|
||||||
|
return true
|
||||||
|
case KeyDown:
|
||||||
|
return true
|
||||||
|
case KeyEnd:
|
||||||
|
return true
|
||||||
|
case KeyEnter:
|
||||||
|
return true
|
||||||
|
case KeyEqual:
|
||||||
|
return true
|
||||||
|
case KeyEscape:
|
||||||
|
return true
|
||||||
|
case KeyF1:
|
||||||
|
return true
|
||||||
|
case KeyF2:
|
||||||
|
return true
|
||||||
|
case KeyF3:
|
||||||
|
return true
|
||||||
|
case KeyF4:
|
||||||
|
return true
|
||||||
|
case KeyF5:
|
||||||
|
return true
|
||||||
|
case KeyF6:
|
||||||
|
return true
|
||||||
|
case KeyF7:
|
||||||
|
return true
|
||||||
|
case KeyF8:
|
||||||
|
return true
|
||||||
|
case KeyF9:
|
||||||
|
return true
|
||||||
|
case KeyF10:
|
||||||
|
return true
|
||||||
|
case KeyF11:
|
||||||
|
return true
|
||||||
|
case KeyF12:
|
||||||
|
return true
|
||||||
|
case KeyGraveAccent:
|
||||||
|
return true
|
||||||
|
case KeyHome:
|
||||||
|
return true
|
||||||
|
case KeyInsert:
|
||||||
|
return true
|
||||||
|
case KeyKP0:
|
||||||
|
return true
|
||||||
|
case KeyKP1:
|
||||||
|
return true
|
||||||
|
case KeyKP2:
|
||||||
|
return true
|
||||||
|
case KeyKP3:
|
||||||
|
return true
|
||||||
|
case KeyKP4:
|
||||||
|
return true
|
||||||
|
case KeyKP5:
|
||||||
|
return true
|
||||||
|
case KeyKP6:
|
||||||
|
return true
|
||||||
|
case KeyKP7:
|
||||||
|
return true
|
||||||
|
case KeyKP8:
|
||||||
|
return true
|
||||||
|
case KeyKP9:
|
||||||
|
return true
|
||||||
|
case KeyKPAdd:
|
||||||
|
return true
|
||||||
|
case KeyKPDecimal:
|
||||||
|
return true
|
||||||
|
case KeyKPDivide:
|
||||||
|
return true
|
||||||
|
case KeyKPEnter:
|
||||||
|
return true
|
||||||
|
case KeyKPEqual:
|
||||||
|
return true
|
||||||
|
case KeyKPMultiply:
|
||||||
|
return true
|
||||||
|
case KeyKPSubtract:
|
||||||
|
return true
|
||||||
|
case KeyLeft:
|
||||||
|
return true
|
||||||
|
case KeyLeftBracket:
|
||||||
|
return true
|
||||||
|
case KeyMenu:
|
||||||
|
return true
|
||||||
|
case KeyMinus:
|
||||||
|
return true
|
||||||
|
case KeyNumLock:
|
||||||
|
return true
|
||||||
|
case KeyPageDown:
|
||||||
|
return true
|
||||||
|
case KeyPageUp:
|
||||||
|
return true
|
||||||
|
case KeyPause:
|
||||||
|
return true
|
||||||
|
case KeyPeriod:
|
||||||
|
return true
|
||||||
|
case KeyPrintScreen:
|
||||||
|
return true
|
||||||
|
case KeyRight:
|
||||||
|
return true
|
||||||
|
case KeyRightBracket:
|
||||||
|
return true
|
||||||
|
case KeyScrollLock:
|
||||||
|
return true
|
||||||
|
case KeySemicolon:
|
||||||
|
return true
|
||||||
|
case KeyShift:
|
||||||
|
return true
|
||||||
|
case KeySlash:
|
||||||
|
return true
|
||||||
|
case KeySpace:
|
||||||
|
return true
|
||||||
|
case KeyTab:
|
||||||
|
return true
|
||||||
|
case KeyUp:
|
||||||
|
return true
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// String returns a string representing the key.
|
// String returns a string representing the key.
|
||||||
//
|
//
|
||||||
// If k is an undefined key, String returns an empty string.
|
// If k is an undefined key, String returns an empty string.
|
||||||
|
Loading…
Reference in New Issue
Block a user