mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
parent
eb5c1ee818
commit
c908685e55
124
genkeys.go
124
genkeys.go
@ -27,12 +27,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/go-gl/glfw/v3.3/glfw"
|
|
||||||
"golang.org/x/mobile/event/key"
|
"golang.org/x/mobile/event/key"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
glfwKeyNameToGLFWKey map[string]glfw.Key
|
glfwKeyNameToGLFWKey map[string]int
|
||||||
uiKeyNameToGLFWKeyName map[string]string
|
uiKeyNameToGLFWKeyName map[string]string
|
||||||
androidKeyToUIKeyName map[int]string
|
androidKeyToUIKeyName map[int]string
|
||||||
iosKeyToUIKeyName map[int]string
|
iosKeyToUIKeyName map[int]string
|
||||||
@ -42,58 +41,58 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
glfwKeyNameToGLFWKey = map[string]glfw.Key{
|
glfwKeyNameToGLFWKey = map[string]int{
|
||||||
"Unknown": glfw.KeyUnknown,
|
"Unknown": -1,
|
||||||
"Space": glfw.KeySpace,
|
"Space": 32,
|
||||||
"Apostrophe": glfw.KeyApostrophe,
|
"Apostrophe": 39,
|
||||||
"Comma": glfw.KeyComma,
|
"Comma": 44,
|
||||||
"Minus": glfw.KeyMinus,
|
"Minus": 45,
|
||||||
"Period": glfw.KeyPeriod,
|
"Period": 46,
|
||||||
"Slash": glfw.KeySlash,
|
"Slash": 47,
|
||||||
"Semicolon": glfw.KeySemicolon,
|
"Semicolon": 59,
|
||||||
"Equal": glfw.KeyEqual,
|
"Equal": 61,
|
||||||
"LeftBracket": glfw.KeyLeftBracket,
|
"LeftBracket": 91,
|
||||||
"Backslash": glfw.KeyBackslash,
|
"Backslash": 92,
|
||||||
"RightBracket": glfw.KeyRightBracket,
|
"RightBracket": 93,
|
||||||
"GraveAccent": glfw.KeyGraveAccent,
|
"GraveAccent": 96,
|
||||||
"World1": glfw.KeyWorld1,
|
"World1": 161,
|
||||||
"World2": glfw.KeyWorld2,
|
"World2": 162,
|
||||||
"Escape": glfw.KeyEscape,
|
"Escape": 256,
|
||||||
"Enter": glfw.KeyEnter,
|
"Enter": 257,
|
||||||
"Tab": glfw.KeyTab,
|
"Tab": 258,
|
||||||
"Backspace": glfw.KeyBackspace,
|
"Backspace": 259,
|
||||||
"Insert": glfw.KeyInsert,
|
"Insert": 260,
|
||||||
"Delete": glfw.KeyDelete,
|
"Delete": 261,
|
||||||
"Right": glfw.KeyRight,
|
"Right": 262,
|
||||||
"Left": glfw.KeyLeft,
|
"Left": 263,
|
||||||
"Down": glfw.KeyDown,
|
"Down": 264,
|
||||||
"Up": glfw.KeyUp,
|
"Up": 265,
|
||||||
"PageUp": glfw.KeyPageUp,
|
"PageUp": 266,
|
||||||
"PageDown": glfw.KeyPageDown,
|
"PageDown": 267,
|
||||||
"Home": glfw.KeyHome,
|
"Home": 268,
|
||||||
"End": glfw.KeyEnd,
|
"End": 269,
|
||||||
"CapsLock": glfw.KeyCapsLock,
|
"CapsLock": 280,
|
||||||
"ScrollLock": glfw.KeyScrollLock,
|
"ScrollLock": 281,
|
||||||
"NumLock": glfw.KeyNumLock,
|
"NumLock": 282,
|
||||||
"PrintScreen": glfw.KeyPrintScreen,
|
"PrintScreen": 283,
|
||||||
"Pause": glfw.KeyPause,
|
"Pause": 284,
|
||||||
"LeftShift": glfw.KeyLeftShift,
|
"LeftShift": 340,
|
||||||
"LeftControl": glfw.KeyLeftControl,
|
"LeftControl": 341,
|
||||||
"LeftAlt": glfw.KeyLeftAlt,
|
"LeftAlt": 342,
|
||||||
"LeftSuper": glfw.KeyLeftSuper,
|
"LeftSuper": 343,
|
||||||
"RightShift": glfw.KeyRightShift,
|
"RightShift": 344,
|
||||||
"RightControl": glfw.KeyRightControl,
|
"RightControl": 345,
|
||||||
"RightAlt": glfw.KeyRightAlt,
|
"RightAlt": 346,
|
||||||
"RightSuper": glfw.KeyRightSuper,
|
"RightSuper": 347,
|
||||||
"Menu": glfw.KeyMenu,
|
"Menu": 348,
|
||||||
"KPDecimal": glfw.KeyKPDecimal,
|
"KPDecimal": 330,
|
||||||
"KPDivide": glfw.KeyKPDivide,
|
"KPDivide": 331,
|
||||||
"KPMultiply": glfw.KeyKPMultiply,
|
"KPMultiply": 332,
|
||||||
"KPSubtract": glfw.KeyKPSubtract,
|
"KPSubtract": 333,
|
||||||
"KPAdd": glfw.KeyKPAdd,
|
"KPAdd": 334,
|
||||||
"KPEnter": glfw.KeyKPEnter,
|
"KPEnter": 335,
|
||||||
"KPEqual": glfw.KeyKPEqual,
|
"KPEqual": 336,
|
||||||
"Last": glfw.KeyLast,
|
"Last": 348,
|
||||||
}
|
}
|
||||||
|
|
||||||
uiKeyNameToGLFWKeyName = map[string]string{
|
uiKeyNameToGLFWKeyName = map[string]string{
|
||||||
@ -384,9 +383,16 @@ func init() {
|
|||||||
"MetaRight": "MetaRight",
|
"MetaRight": "MetaRight",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
glfwKey0 = 48
|
||||||
|
glfwKeyA = 65
|
||||||
|
glfwKeyF1 = 290
|
||||||
|
glfwKeyKP0 = 320
|
||||||
|
)
|
||||||
|
|
||||||
// ASCII: 0 - 9
|
// ASCII: 0 - 9
|
||||||
for c := '0'; c <= '9'; c++ {
|
for c := '0'; c <= '9'; c++ {
|
||||||
glfwKeyNameToGLFWKey[string(c)] = glfw.Key0 + glfw.Key(c) - '0'
|
glfwKeyNameToGLFWKey[string(c)] = int(glfwKey0 + c - '0')
|
||||||
name := "Digit" + string(c)
|
name := "Digit" + string(c)
|
||||||
uiKeyNameToGLFWKeyName[name] = string(c)
|
uiKeyNameToGLFWKeyName[name] = string(c)
|
||||||
androidKeyToUIKeyName[7+int(c)-'0'] = name
|
androidKeyToUIKeyName[7+int(c)-'0'] = name
|
||||||
@ -404,7 +410,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
// ASCII: A - Z
|
// ASCII: A - Z
|
||||||
for c := 'A'; c <= 'Z'; c++ {
|
for c := 'A'; c <= 'Z'; c++ {
|
||||||
glfwKeyNameToGLFWKey[string(c)] = glfw.KeyA + glfw.Key(c) - 'A'
|
glfwKeyNameToGLFWKey[string(c)] = int(glfwKeyA + c - 'A')
|
||||||
uiKeyNameToGLFWKeyName[string(c)] = string(c)
|
uiKeyNameToGLFWKeyName[string(c)] = string(c)
|
||||||
androidKeyToUIKeyName[29+int(c)-'A'] = string(c)
|
androidKeyToUIKeyName[29+int(c)-'A'] = string(c)
|
||||||
iosKeyToUIKeyName[0x04+int(c)-'A'] = string(c)
|
iosKeyToUIKeyName[0x04+int(c)-'A'] = string(c)
|
||||||
@ -414,7 +420,7 @@ func init() {
|
|||||||
// Function keys
|
// Function keys
|
||||||
for i := 1; i <= 12; i++ {
|
for i := 1; i <= 12; i++ {
|
||||||
name := "F" + strconv.Itoa(i)
|
name := "F" + strconv.Itoa(i)
|
||||||
glfwKeyNameToGLFWKey[name] = glfw.KeyF1 + glfw.Key(i) - 1
|
glfwKeyNameToGLFWKey[name] = glfwKeyF1 + i - 1
|
||||||
uiKeyNameToGLFWKeyName[name] = name
|
uiKeyNameToGLFWKeyName[name] = name
|
||||||
androidKeyToUIKeyName[131+i-1] = name
|
androidKeyToUIKeyName[131+i-1] = name
|
||||||
// Note: iOS keys go up to F24 (with F13 being 0x68 and increasing from there),
|
// Note: iOS keys go up to F24 (with F13 being 0x68 and increasing from there),
|
||||||
@ -427,7 +433,7 @@ func init() {
|
|||||||
// https://www.w3.org/TR/uievents-code/#key-numpad-section
|
// https://www.w3.org/TR/uievents-code/#key-numpad-section
|
||||||
for c := '0'; c <= '9'; c++ {
|
for c := '0'; c <= '9'; c++ {
|
||||||
name := "Numpad" + string(c)
|
name := "Numpad" + string(c)
|
||||||
glfwKeyNameToGLFWKey["KP"+string(c)] = glfw.KeyKP0 + glfw.Key(c) - '0'
|
glfwKeyNameToGLFWKey["KP"+string(c)] = int(glfwKeyKP0 + c - '0')
|
||||||
uiKeyNameToGLFWKeyName[name] = "KP" + string(c)
|
uiKeyNameToGLFWKeyName[name] = "KP" + string(c)
|
||||||
androidKeyToUIKeyName[144+int(c)-'0'] = name
|
androidKeyToUIKeyName[144+int(c)-'0'] = name
|
||||||
// Gomobile's key code (= USB HID key codes) has successive key codes for 1, 2, ..., 9, 0
|
// Gomobile's key code (= USB HID key codes) has successive key codes for 1, 2, ..., 9, 0
|
||||||
@ -873,7 +879,7 @@ func main() {
|
|||||||
EbitengineKeyNames []string
|
EbitengineKeyNames []string
|
||||||
EbitengineKeyNamesWithoutOld []string
|
EbitengineKeyNamesWithoutOld []string
|
||||||
EbitengineKeyNamesWithoutMods []string
|
EbitengineKeyNamesWithoutMods []string
|
||||||
GLFWKeyNameToGLFWKey map[string]glfw.Key
|
GLFWKeyNameToGLFWKey map[string]int
|
||||||
UIKeyNames []string
|
UIKeyNames []string
|
||||||
UIKeyNameToGLFWKeyName map[string]string
|
UIKeyNameToGLFWKeyName map[string]string
|
||||||
AndroidKeyToUIKeyName map[int]string
|
AndroidKeyToUIKeyName map[int]string
|
||||||
|
Loading…
Reference in New Issue
Block a user