ebiten/keys.go

928 lines
20 KiB
Go
Raw Normal View History

2016-08-26 17:50:26 +02:00
// Copyright 2013 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2014-12-14 08:53:32 +01:00
// Code generated by genkeys.go using 'go generate'. DO NOT EDIT.
2015-01-07 15:21:52 +01:00
2014-12-14 08:53:32 +01:00
package ebiten
2015-01-01 17:20:20 +01:00
import (
"strings"
2020-10-03 19:35:13 +02:00
"github.com/hajimehoshi/ebiten/v2/internal/driver"
2015-01-01 17:20:20 +01:00
)
2014-12-14 14:05:44 +01:00
// A Key represents a keyboard key.
2017-04-10 03:45:04 +02:00
// These keys represent pysical keys of US keyboard.
2017-07-23 15:49:04 +02:00
// For example, KeyQ represents Q key on US keyboards and ' (quote) key on Dvorak keyboards.
2014-12-14 08:53:32 +01:00
type Key int
2018-04-13 19:29:18 +02:00
// Keys.
2014-12-14 08:53:32 +01:00
const (
KeyA Key = Key(driver.KeyA)
KeyB Key = Key(driver.KeyB)
KeyC Key = Key(driver.KeyC)
KeyD Key = Key(driver.KeyD)
KeyE Key = Key(driver.KeyE)
KeyF Key = Key(driver.KeyF)
KeyG Key = Key(driver.KeyG)
KeyH Key = Key(driver.KeyH)
KeyI Key = Key(driver.KeyI)
KeyJ Key = Key(driver.KeyJ)
KeyK Key = Key(driver.KeyK)
KeyL Key = Key(driver.KeyL)
KeyM Key = Key(driver.KeyM)
KeyN Key = Key(driver.KeyN)
KeyO Key = Key(driver.KeyO)
KeyP Key = Key(driver.KeyP)
KeyQ Key = Key(driver.KeyQ)
KeyR Key = Key(driver.KeyR)
KeyS Key = Key(driver.KeyS)
KeyT Key = Key(driver.KeyT)
KeyU Key = Key(driver.KeyU)
KeyV Key = Key(driver.KeyV)
KeyW Key = Key(driver.KeyW)
KeyX Key = Key(driver.KeyX)
KeyY Key = Key(driver.KeyY)
KeyZ Key = Key(driver.KeyZ)
KeyAltLeft Key = Key(driver.KeyAltLeft)
KeyAltRight Key = Key(driver.KeyAltRight)
KeyArrowDown Key = Key(driver.KeyArrowDown)
KeyArrowLeft Key = Key(driver.KeyArrowLeft)
KeyArrowRight Key = Key(driver.KeyArrowRight)
KeyArrowUp Key = Key(driver.KeyArrowUp)
KeyBackquote Key = Key(driver.KeyBackquote)
KeyBackslash Key = Key(driver.KeyBackslash)
KeyBackspace Key = Key(driver.KeyBackspace)
KeyBracketLeft Key = Key(driver.KeyBracketLeft)
KeyBracketRight Key = Key(driver.KeyBracketRight)
KeyCapsLock Key = Key(driver.KeyCapsLock)
KeyComma Key = Key(driver.KeyComma)
KeyContextMenu Key = Key(driver.KeyContextMenu)
KeyControlLeft Key = Key(driver.KeyControlLeft)
KeyControlRight Key = Key(driver.KeyControlRight)
KeyDelete Key = Key(driver.KeyDelete)
KeyDigit0 Key = Key(driver.KeyDigit0)
KeyDigit1 Key = Key(driver.KeyDigit1)
KeyDigit2 Key = Key(driver.KeyDigit2)
KeyDigit3 Key = Key(driver.KeyDigit3)
KeyDigit4 Key = Key(driver.KeyDigit4)
KeyDigit5 Key = Key(driver.KeyDigit5)
KeyDigit6 Key = Key(driver.KeyDigit6)
KeyDigit7 Key = Key(driver.KeyDigit7)
KeyDigit8 Key = Key(driver.KeyDigit8)
KeyDigit9 Key = Key(driver.KeyDigit9)
KeyEnd Key = Key(driver.KeyEnd)
KeyEnter Key = Key(driver.KeyEnter)
KeyEqual Key = Key(driver.KeyEqual)
KeyEscape Key = Key(driver.KeyEscape)
KeyF1 Key = Key(driver.KeyF1)
KeyF2 Key = Key(driver.KeyF2)
KeyF3 Key = Key(driver.KeyF3)
KeyF4 Key = Key(driver.KeyF4)
KeyF5 Key = Key(driver.KeyF5)
KeyF6 Key = Key(driver.KeyF6)
KeyF7 Key = Key(driver.KeyF7)
KeyF8 Key = Key(driver.KeyF8)
KeyF9 Key = Key(driver.KeyF9)
KeyF10 Key = Key(driver.KeyF10)
KeyF11 Key = Key(driver.KeyF11)
KeyF12 Key = Key(driver.KeyF12)
KeyHome Key = Key(driver.KeyHome)
KeyInsert Key = Key(driver.KeyInsert)
KeyMetaLeft Key = Key(driver.KeyMetaLeft)
KeyMetaRight Key = Key(driver.KeyMetaRight)
KeyMinus Key = Key(driver.KeyMinus)
KeyNumLock Key = Key(driver.KeyNumLock)
KeyNumpad0 Key = Key(driver.KeyNumpad0)
KeyNumpad1 Key = Key(driver.KeyNumpad1)
KeyNumpad2 Key = Key(driver.KeyNumpad2)
KeyNumpad3 Key = Key(driver.KeyNumpad3)
KeyNumpad4 Key = Key(driver.KeyNumpad4)
KeyNumpad5 Key = Key(driver.KeyNumpad5)
KeyNumpad6 Key = Key(driver.KeyNumpad6)
KeyNumpad7 Key = Key(driver.KeyNumpad7)
KeyNumpad8 Key = Key(driver.KeyNumpad8)
KeyNumpad9 Key = Key(driver.KeyNumpad9)
KeyNumpadAdd Key = Key(driver.KeyNumpadAdd)
KeyNumpadDecimal Key = Key(driver.KeyNumpadDecimal)
KeyNumpadDivide Key = Key(driver.KeyNumpadDivide)
KeyNumpadEnter Key = Key(driver.KeyNumpadEnter)
KeyNumpadEqual Key = Key(driver.KeyNumpadEqual)
KeyNumpadMultiply Key = Key(driver.KeyNumpadMultiply)
KeyNumpadSubtract Key = Key(driver.KeyNumpadSubtract)
KeyPageDown Key = Key(driver.KeyPageDown)
KeyPageUp Key = Key(driver.KeyPageUp)
KeyPause Key = Key(driver.KeyPause)
KeyPeriod Key = Key(driver.KeyPeriod)
KeyPrintScreen Key = Key(driver.KeyPrintScreen)
KeyQuote Key = Key(driver.KeyQuote)
KeyScrollLock Key = Key(driver.KeyScrollLock)
KeySemicolon Key = Key(driver.KeySemicolon)
KeyShiftLeft Key = Key(driver.KeyShiftLeft)
KeyShiftRight Key = Key(driver.KeyShiftRight)
KeySlash Key = Key(driver.KeySlash)
KeySpace Key = Key(driver.KeySpace)
KeyTab Key = Key(driver.KeyTab)
KeyAlt Key = Key(driver.KeyReserved0)
KeyControl Key = Key(driver.KeyReserved1)
KeyShift Key = Key(driver.KeyReserved2)
KeyMeta Key = Key(driver.KeyReserved3)
KeyMax Key = KeyMeta
// Keys for backward compatibility.
2021-07-09 20:19:23 +02:00
// Deprecated: as of v2.1.
Key0 Key = Key(driver.KeyDigit0)
Key1 Key = Key(driver.KeyDigit1)
Key2 Key = Key(driver.KeyDigit2)
Key3 Key = Key(driver.KeyDigit3)
Key4 Key = Key(driver.KeyDigit4)
Key5 Key = Key(driver.KeyDigit5)
Key6 Key = Key(driver.KeyDigit6)
Key7 Key = Key(driver.KeyDigit7)
Key8 Key = Key(driver.KeyDigit8)
Key9 Key = Key(driver.KeyDigit9)
KeyApostrophe Key = Key(driver.KeyQuote)
KeyDown Key = Key(driver.KeyArrowDown)
KeyGraveAccent Key = Key(driver.KeyBackquote)
KeyKP0 Key = Key(driver.KeyNumpad0)
KeyKP1 Key = Key(driver.KeyNumpad1)
KeyKP2 Key = Key(driver.KeyNumpad2)
KeyKP3 Key = Key(driver.KeyNumpad3)
KeyKP4 Key = Key(driver.KeyNumpad4)
KeyKP5 Key = Key(driver.KeyNumpad5)
KeyKP6 Key = Key(driver.KeyNumpad6)
KeyKP7 Key = Key(driver.KeyNumpad7)
KeyKP8 Key = Key(driver.KeyNumpad8)
KeyKP9 Key = Key(driver.KeyNumpad9)
KeyKPDecimal Key = Key(driver.KeyNumpadDecimal)
KeyKPDivide Key = Key(driver.KeyNumpadDivide)
KeyKPEnter Key = Key(driver.KeyNumpadEnter)
KeyKPEqual Key = Key(driver.KeyNumpadEqual)
KeyKPMultiply Key = Key(driver.KeyNumpadMultiply)
KeyKPSubtract Key = Key(driver.KeyNumpadSubtract)
KeyLeft Key = Key(driver.KeyArrowLeft)
KeyLeftBracket Key = Key(driver.KeyBracketLeft)
KeyMenu Key = Key(driver.KeyContextMenu)
KeyRight Key = Key(driver.KeyArrowRight)
KeyRightBracket Key = Key(driver.KeyBracketRight)
KeyUp Key = Key(driver.KeyArrowUp)
2014-12-14 08:53:32 +01:00
)
func (k Key) isValid() bool {
switch k {
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 KeyAltLeft:
return true
case KeyAltRight:
return true
case KeyArrowDown:
return true
case KeyArrowLeft:
return true
case KeyArrowRight:
return true
case KeyArrowUp:
return true
case KeyBackquote:
return true
case KeyBackslash:
return true
case KeyBackspace:
return true
case KeyBracketLeft:
return true
case KeyBracketRight:
return true
case KeyCapsLock:
return true
case KeyComma:
return true
case KeyContextMenu:
return true
case KeyControl:
return true
case KeyControlLeft:
return true
case KeyControlRight:
return true
case KeyDelete:
return true
case KeyDigit0:
return true
case KeyDigit1:
return true
case KeyDigit2:
return true
case KeyDigit3:
return true
case KeyDigit4:
return true
case KeyDigit5:
return true
case KeyDigit6:
return true
case KeyDigit7:
return true
case KeyDigit8:
return true
case KeyDigit9:
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 KeyHome:
return true
case KeyInsert:
return true
case KeyMeta:
return true
case KeyMetaLeft:
return true
case KeyMetaRight:
return true
case KeyMinus:
return true
case KeyNumLock:
return true
case KeyNumpad0:
return true
case KeyNumpad1:
return true
case KeyNumpad2:
return true
case KeyNumpad3:
return true
case KeyNumpad4:
return true
case KeyNumpad5:
return true
case KeyNumpad6:
return true
case KeyNumpad7:
return true
case KeyNumpad8:
return true
case KeyNumpad9:
return true
case KeyNumpadAdd:
return true
case KeyNumpadDecimal:
return true
case KeyNumpadDivide:
return true
case KeyNumpadEnter:
return true
case KeyNumpadEqual:
return true
case KeyNumpadMultiply:
return true
case KeyNumpadSubtract:
return true
case KeyPageDown:
return true
case KeyPageUp:
return true
case KeyPause:
return true
case KeyPeriod:
return true
case KeyPrintScreen:
return true
case KeyQuote:
return true
case KeyScrollLock:
return true
case KeySemicolon:
return true
case KeyShift:
return true
case KeyShiftLeft:
return true
case KeyShiftRight:
return true
case KeySlash:
return true
case KeySpace:
return true
case KeyTab:
return true
default:
return false
}
}
2018-04-13 20:20:43 +02:00
// 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 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 KeyAltLeft:
return "AltLeft"
case KeyAltRight:
return "AltRight"
case KeyArrowDown:
return "ArrowDown"
case KeyArrowLeft:
return "ArrowLeft"
case KeyArrowRight:
return "ArrowRight"
case KeyArrowUp:
return "ArrowUp"
case KeyBackquote:
return "Backquote"
2018-04-13 20:20:43 +02:00
case KeyBackslash:
return "Backslash"
case KeyBackspace:
return "Backspace"
case KeyBracketLeft:
return "BracketLeft"
case KeyBracketRight:
return "BracketRight"
2018-04-13 20:20:43 +02:00
case KeyCapsLock:
return "CapsLock"
case KeyComma:
return "Comma"
case KeyContextMenu:
return "ContextMenu"
2018-04-13 20:20:43 +02:00
case KeyControl:
return "Control"
case KeyControlLeft:
return "ControlLeft"
case KeyControlRight:
return "ControlRight"
2018-04-13 20:20:43 +02:00
case KeyDelete:
return "Delete"
case KeyDigit0:
return "Digit0"
case KeyDigit1:
return "Digit1"
case KeyDigit2:
return "Digit2"
case KeyDigit3:
return "Digit3"
case KeyDigit4:
return "Digit4"
case KeyDigit5:
return "Digit5"
case KeyDigit6:
return "Digit6"
case KeyDigit7:
return "Digit7"
case KeyDigit8:
return "Digit8"
case KeyDigit9:
return "Digit9"
2018-04-13 20:20:43 +02:00
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 KeyHome:
return "Home"
case KeyInsert:
return "Insert"
case KeyMeta:
return "Meta"
case KeyMetaLeft:
return "MetaLeft"
case KeyMetaRight:
return "MetaRight"
2018-04-13 20:20:43 +02:00
case KeyMinus:
return "Minus"
case KeyNumLock:
return "NumLock"
case KeyNumpad0:
return "Numpad0"
case KeyNumpad1:
return "Numpad1"
case KeyNumpad2:
return "Numpad2"
case KeyNumpad3:
return "Numpad3"
case KeyNumpad4:
return "Numpad4"
case KeyNumpad5:
return "Numpad5"
case KeyNumpad6:
return "Numpad6"
case KeyNumpad7:
return "Numpad7"
case KeyNumpad8:
return "Numpad8"
case KeyNumpad9:
return "Numpad9"
case KeyNumpadAdd:
return "NumpadAdd"
case KeyNumpadDecimal:
return "NumpadDecimal"
case KeyNumpadDivide:
return "NumpadDivide"
case KeyNumpadEnter:
return "NumpadEnter"
case KeyNumpadEqual:
return "NumpadEqual"
case KeyNumpadMultiply:
return "NumpadMultiply"
case KeyNumpadSubtract:
return "NumpadSubtract"
2018-04-13 20:20:43 +02:00
case KeyPageDown:
return "PageDown"
case KeyPageUp:
return "PageUp"
case KeyPause:
return "Pause"
2018-04-13 20:20:43 +02:00
case KeyPeriod:
return "Period"
case KeyPrintScreen:
return "PrintScreen"
case KeyQuote:
return "Quote"
case KeyScrollLock:
return "ScrollLock"
2018-04-13 20:20:43 +02:00
case KeySemicolon:
return "Semicolon"
case KeyShift:
return "Shift"
case KeyShiftLeft:
return "ShiftLeft"
case KeyShiftRight:
return "ShiftRight"
2018-04-13 20:20:43 +02:00
case KeySlash:
return "Slash"
case KeySpace:
return "Space"
case KeyTab:
return "Tab"
}
return ""
}
2020-02-19 02:42:42 +01:00
func keyNameToKeyCode(name string) (Key, bool) {
switch strings.ToLower(name) {
case "0":
return Key0, true
case "1":
return Key1, true
case "2":
return Key2, true
case "3":
return Key3, true
case "4":
return Key4, true
case "5":
return Key5, true
case "6":
return Key6, true
case "7":
return Key7, true
case "8":
return Key8, true
case "9":
return Key9, true
case "a":
return KeyA, true
case "b":
return KeyB, true
case "c":
return KeyC, true
case "d":
return KeyD, true
case "e":
return KeyE, true
case "f":
return KeyF, true
case "g":
return KeyG, true
case "h":
return KeyH, true
case "i":
return KeyI, true
case "j":
return KeyJ, true
case "k":
return KeyK, true
case "l":
return KeyL, true
case "m":
return KeyM, true
case "n":
return KeyN, true
case "o":
return KeyO, true
case "p":
return KeyP, true
case "q":
return KeyQ, true
case "r":
return KeyR, true
case "s":
return KeyS, true
case "t":
return KeyT, true
case "u":
return KeyU, true
case "v":
return KeyV, true
case "w":
return KeyW, true
case "x":
return KeyX, true
case "y":
return KeyY, true
case "z":
return KeyZ, true
case "alt":
return KeyAlt, true
case "altleft":
return KeyAltLeft, true
case "altright":
return KeyAltRight, true
case "apostrophe":
return KeyApostrophe, true
case "arrowdown":
return KeyArrowDown, true
case "arrowleft":
return KeyArrowLeft, true
case "arrowright":
return KeyArrowRight, true
case "arrowup":
return KeyArrowUp, true
case "backquote":
return KeyBackquote, true
case "backslash":
return KeyBackslash, true
case "backspace":
return KeyBackspace, true
case "bracketleft":
return KeyBracketLeft, true
case "bracketright":
return KeyBracketRight, true
case "capslock":
return KeyCapsLock, true
case "comma":
return KeyComma, true
case "contextmenu":
return KeyContextMenu, true
case "control":
return KeyControl, true
case "controlleft":
return KeyControlLeft, true
case "controlright":
return KeyControlRight, true
case "delete":
return KeyDelete, true
case "digit0":
return KeyDigit0, true
case "digit1":
return KeyDigit1, true
case "digit2":
return KeyDigit2, true
case "digit3":
return KeyDigit3, true
case "digit4":
return KeyDigit4, true
case "digit5":
return KeyDigit5, true
case "digit6":
return KeyDigit6, true
case "digit7":
return KeyDigit7, true
case "digit8":
return KeyDigit8, true
case "digit9":
return KeyDigit9, true
case "down":
return KeyDown, true
case "end":
return KeyEnd, true
case "enter":
return KeyEnter, true
case "equal":
return KeyEqual, true
case "escape":
return KeyEscape, true
case "f1":
return KeyF1, true
case "f2":
return KeyF2, true
case "f3":
return KeyF3, true
case "f4":
return KeyF4, true
case "f5":
return KeyF5, true
case "f6":
return KeyF6, true
case "f7":
return KeyF7, true
case "f8":
return KeyF8, true
case "f9":
return KeyF9, true
case "f10":
return KeyF10, true
case "f11":
return KeyF11, true
case "f12":
return KeyF12, true
case "graveaccent":
return KeyGraveAccent, true
case "home":
return KeyHome, true
case "insert":
return KeyInsert, true
case "kp0":
return KeyKP0, true
case "kp1":
return KeyKP1, true
case "kp2":
return KeyKP2, true
case "kp3":
return KeyKP3, true
case "kp4":
return KeyKP4, true
case "kp5":
return KeyKP5, true
case "kp6":
return KeyKP6, true
case "kp7":
return KeyKP7, true
case "kp8":
return KeyKP8, true
case "kp9":
return KeyKP9, true
case "kpdecimal":
return KeyKPDecimal, true
case "kpdivide":
return KeyKPDivide, true
case "kpenter":
return KeyKPEnter, true
case "kpequal":
return KeyKPEqual, true
case "kpmultiply":
return KeyKPMultiply, true
case "kpsubtract":
return KeyKPSubtract, true
case "left":
return KeyLeft, true
case "leftbracket":
return KeyLeftBracket, true
case "menu":
return KeyMenu, true
case "meta":
return KeyMeta, true
case "metaleft":
return KeyMetaLeft, true
case "metaright":
return KeyMetaRight, true
case "minus":
return KeyMinus, true
2018-04-12 18:18:54 +02:00
case "numlock":
return KeyNumLock, true
case "numpad0":
return KeyNumpad0, true
case "numpad1":
return KeyNumpad1, true
case "numpad2":
return KeyNumpad2, true
case "numpad3":
return KeyNumpad3, true
case "numpad4":
return KeyNumpad4, true
case "numpad5":
return KeyNumpad5, true
case "numpad6":
return KeyNumpad6, true
case "numpad7":
return KeyNumpad7, true
case "numpad8":
return KeyNumpad8, true
case "numpad9":
return KeyNumpad9, true
case "numpadadd":
return KeyNumpadAdd, true
case "numpaddecimal":
return KeyNumpadDecimal, true
case "numpaddivide":
return KeyNumpadDivide, true
case "numpadenter":
return KeyNumpadEnter, true
case "numpadequal":
return KeyNumpadEqual, true
case "numpadmultiply":
return KeyNumpadMultiply, true
case "numpadsubtract":
return KeyNumpadSubtract, true
case "pagedown":
return KeyPageDown, true
case "pageup":
return KeyPageUp, true
case "pause":
return KeyPause, true
case "period":
return KeyPeriod, true
case "printscreen":
return KeyPrintScreen, true
case "quote":
return KeyQuote, true
case "right":
return KeyRight, true
case "rightbracket":
return KeyRightBracket, true
case "scrolllock":
return KeyScrollLock, true
case "semicolon":
return KeySemicolon, true
case "shift":
return KeyShift, true
case "shiftleft":
return KeyShiftLeft, true
case "shiftright":
return KeyShiftRight, true
case "slash":
return KeySlash, true
case "space":
return KeySpace, true
case "tab":
return KeyTab, true
case "up":
return KeyUp, true
}
return 0, false
}