ebiten: Add Key{Left,Right}{Alt,Control,Shift,Super}

Closes #1561
This commit is contained in:
Hajime Hoshi 2021-04-10 19:59:30 +09:00
parent d46b0c5b49
commit 45f10f134f
2 changed files with 60 additions and 21 deletions

View File

@ -663,30 +663,13 @@ func main() {
ebitenKeyNames := []string{} ebitenKeyNames := []string{}
ebitenKeyNamesWithoutMods := []string{} ebitenKeyNamesWithoutMods := []string{}
driverKeyNames := []string{} driverKeyNames := []string{}
for name := range driverKeyNameToJSKey { for name := range driverKeyNameToJSKey {
driverKeyNames = append(driverKeyNames, name) driverKeyNames = append(driverKeyNames, name)
if !strings.HasSuffix(name, "Alt") && !strings.HasSuffix(name, "Control") && !strings.HasSuffix(name, "Shift") && !strings.HasSuffix(name, "Super") {
ebitenKeyNames = append(ebitenKeyNames, name) 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
}
if name == "LeftSuper" {
ebitenKeyNames = append(ebitenKeyNames, "Super")
continue
}
} }
ebitenKeyNames = append(ebitenKeyNames, "Alt", "Control", "Shift", "Super")
sort.Slice(ebitenKeyNames, keyNamesLess(ebitenKeyNames)) sort.Slice(ebitenKeyNames, keyNamesLess(ebitenKeyNames))
sort.Slice(ebitenKeyNamesWithoutMods, keyNamesLess(ebitenKeyNamesWithoutMods)) sort.Slice(ebitenKeyNamesWithoutMods, keyNamesLess(ebitenKeyNamesWithoutMods))

56
keys.go
View File

@ -109,7 +109,11 @@ const (
KeyKPMultiply Key = Key(driver.KeyKPMultiply) KeyKPMultiply Key = Key(driver.KeyKPMultiply)
KeyKPSubtract Key = Key(driver.KeyKPSubtract) KeyKPSubtract Key = Key(driver.KeyKPSubtract)
KeyLeft Key = Key(driver.KeyLeft) KeyLeft Key = Key(driver.KeyLeft)
KeyLeftAlt Key = Key(driver.KeyLeftAlt)
KeyLeftBracket Key = Key(driver.KeyLeftBracket) KeyLeftBracket Key = Key(driver.KeyLeftBracket)
KeyLeftControl Key = Key(driver.KeyLeftControl)
KeyLeftShift Key = Key(driver.KeyLeftShift)
KeyLeftSuper Key = Key(driver.KeyLeftSuper)
KeyMenu Key = Key(driver.KeyMenu) KeyMenu Key = Key(driver.KeyMenu)
KeyMinus Key = Key(driver.KeyMinus) KeyMinus Key = Key(driver.KeyMinus)
KeyNumLock Key = Key(driver.KeyNumLock) KeyNumLock Key = Key(driver.KeyNumLock)
@ -119,7 +123,11 @@ const (
KeyPeriod Key = Key(driver.KeyPeriod) KeyPeriod Key = Key(driver.KeyPeriod)
KeyPrintScreen Key = Key(driver.KeyPrintScreen) KeyPrintScreen Key = Key(driver.KeyPrintScreen)
KeyRight Key = Key(driver.KeyRight) KeyRight Key = Key(driver.KeyRight)
KeyRightAlt Key = Key(driver.KeyRightAlt)
KeyRightBracket Key = Key(driver.KeyRightBracket) KeyRightBracket Key = Key(driver.KeyRightBracket)
KeyRightControl Key = Key(driver.KeyRightControl)
KeyRightShift Key = Key(driver.KeyRightShift)
KeyRightSuper Key = Key(driver.KeyRightSuper)
KeyScrollLock Key = Key(driver.KeyScrollLock) KeyScrollLock Key = Key(driver.KeyScrollLock)
KeySemicolon Key = Key(driver.KeySemicolon) KeySemicolon Key = Key(driver.KeySemicolon)
KeySlash Key = Key(driver.KeySlash) KeySlash Key = Key(driver.KeySlash)
@ -299,8 +307,16 @@ func (k Key) isValid() bool {
return true return true
case KeyLeft: case KeyLeft:
return true return true
case KeyLeftAlt:
return true
case KeyLeftBracket: case KeyLeftBracket:
return true return true
case KeyLeftControl:
return true
case KeyLeftShift:
return true
case KeyLeftSuper:
return true
case KeyMenu: case KeyMenu:
return true return true
case KeyMinus: case KeyMinus:
@ -319,8 +335,16 @@ func (k Key) isValid() bool {
return true return true
case KeyRight: case KeyRight:
return true return true
case KeyRightAlt:
return true
case KeyRightBracket: case KeyRightBracket:
return true return true
case KeyRightControl:
return true
case KeyRightShift:
return true
case KeyRightSuper:
return true
case KeyScrollLock: case KeyScrollLock:
return true return true
case KeySemicolon: case KeySemicolon:
@ -512,8 +536,16 @@ func (k Key) String() string {
return "KPSubtract" return "KPSubtract"
case KeyLeft: case KeyLeft:
return "Left" return "Left"
case KeyLeftAlt:
return "LeftAlt"
case KeyLeftBracket: case KeyLeftBracket:
return "LeftBracket" return "LeftBracket"
case KeyLeftControl:
return "LeftControl"
case KeyLeftShift:
return "LeftShift"
case KeyLeftSuper:
return "LeftSuper"
case KeyMenu: case KeyMenu:
return "Menu" return "Menu"
case KeyMinus: case KeyMinus:
@ -532,8 +564,16 @@ func (k Key) String() string {
return "PrintScreen" return "PrintScreen"
case KeyRight: case KeyRight:
return "Right" return "Right"
case KeyRightAlt:
return "RightAlt"
case KeyRightBracket: case KeyRightBracket:
return "RightBracket" return "RightBracket"
case KeyRightControl:
return "RightControl"
case KeyRightShift:
return "RightShift"
case KeyRightSuper:
return "RightSuper"
case KeyScrollLock: case KeyScrollLock:
return "ScrollLock" return "ScrollLock"
case KeySemicolon: case KeySemicolon:
@ -720,8 +760,16 @@ func keyNameToKeyCode(name string) (Key, bool) {
return KeyKPSubtract, true return KeyKPSubtract, true
case "left": case "left":
return KeyLeft, true return KeyLeft, true
case "leftalt":
return KeyLeftAlt, true
case "leftbracket": case "leftbracket":
return KeyLeftBracket, true return KeyLeftBracket, true
case "leftcontrol":
return KeyLeftControl, true
case "leftshift":
return KeyLeftShift, true
case "leftsuper":
return KeyLeftSuper, true
case "menu": case "menu":
return KeyMenu, true return KeyMenu, true
case "minus": case "minus":
@ -740,8 +788,16 @@ func keyNameToKeyCode(name string) (Key, bool) {
return KeyPrintScreen, true return KeyPrintScreen, true
case "right": case "right":
return KeyRight, true return KeyRight, true
case "rightalt":
return KeyRightAlt, true
case "rightbracket": case "rightbracket":
return KeyRightBracket, true return KeyRightBracket, true
case "rightcontrol":
return KeyRightControl, true
case "rightshift":
return KeyRightShift, true
case "rightsuper":
return KeyRightSuper, true
case "scrolllock": case "scrolllock":
return KeyScrollLock, true return KeyScrollLock, true
case "semicolon": case "semicolon":