mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
9ad7a55db2
commit
3152d88477
79
genkeys.go
79
genkeys.go
@ -37,7 +37,6 @@ var (
|
|||||||
androidKeyToUIKeyName map[int]string
|
androidKeyToUIKeyName map[int]string
|
||||||
gbuildKeyToUIKeyName map[key.Code]string
|
gbuildKeyToUIKeyName map[key.Code]string
|
||||||
uiKeyNameToJSKey map[string]string
|
uiKeyNameToJSKey map[string]string
|
||||||
edgeKeyCodeToName map[int]string
|
|
||||||
oldEbitengineKeyNameToUIKeyName map[string]string
|
oldEbitengineKeyNameToUIKeyName map[string]string
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -390,77 +389,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
|
|
||||||
// TODO: How should we treat modifier keys? Now 'left' modifier keys are available.
|
|
||||||
edgeKeyCodeToName = map[int]string{
|
|
||||||
0xbc: "Comma",
|
|
||||||
0xbe: "Period",
|
|
||||||
0x12: "AltLeft",
|
|
||||||
0x14: "CapsLock",
|
|
||||||
0x11: "ControlLeft",
|
|
||||||
0x10: "ShiftLeft",
|
|
||||||
0x0D: "Enter",
|
|
||||||
0x20: "Space",
|
|
||||||
0x09: "Tab",
|
|
||||||
0x2E: "Delete",
|
|
||||||
0x23: "End",
|
|
||||||
0x24: "Home",
|
|
||||||
0x2D: "Insert",
|
|
||||||
0x22: "PageDown",
|
|
||||||
0x21: "PageUp",
|
|
||||||
0x28: "ArrowDown",
|
|
||||||
0x25: "ArrowLeft",
|
|
||||||
0x27: "ArrowRight",
|
|
||||||
0x26: "ArrowUp",
|
|
||||||
0x1B: "Escape",
|
|
||||||
0xde: "Quote",
|
|
||||||
0xbd: "Minus",
|
|
||||||
0xbf: "Slash",
|
|
||||||
0xba: "Semicolon",
|
|
||||||
0xbb: "Equal",
|
|
||||||
0xdb: "BracketLeft",
|
|
||||||
0xdc: "Backslash",
|
|
||||||
0xdd: "BracketRight",
|
|
||||||
0xc0: "Backquote",
|
|
||||||
0x08: "Backspace",
|
|
||||||
0x90: "NumLock",
|
|
||||||
0x6b: "NumpadAdd",
|
|
||||||
0x6e: "NumpadDecimal",
|
|
||||||
0x6f: "NumpadDivide",
|
|
||||||
0x6a: "NumpadMultiply",
|
|
||||||
0x6d: "NumpadSubtract",
|
|
||||||
0x13: "Pause",
|
|
||||||
0x91: "ScrollLock",
|
|
||||||
0x5d: "ContextMenu",
|
|
||||||
0x5b: "MetaLeft",
|
|
||||||
0x5c: "MetaRight",
|
|
||||||
|
|
||||||
// On Edge, this key does not work. PrintScreen works only on keyup event.
|
|
||||||
// 0x2C: "PrintScreen",
|
|
||||||
|
|
||||||
// On Edge, it is impossible to tell NumpadEnter and Enter / NumpadEqual and Equal.
|
|
||||||
// 0x0d: "NumpadEnter",
|
|
||||||
// 0x0c: "NumpadEqual",
|
|
||||||
}
|
|
||||||
// ASCII: 0 - 9
|
|
||||||
for c := '0'; c <= '9'; c++ {
|
|
||||||
edgeKeyCodeToName[int(c)] = "Digit" + string(c)
|
|
||||||
}
|
|
||||||
// ASCII: A - Z
|
|
||||||
for c := 'A'; c <= 'Z'; c++ {
|
|
||||||
edgeKeyCodeToName[int(c)] = string(c)
|
|
||||||
}
|
|
||||||
// Function keys
|
|
||||||
for i := 1; i <= 12; i++ {
|
|
||||||
edgeKeyCodeToName[0x70+i-1] = "F" + strconv.Itoa(i)
|
|
||||||
}
|
|
||||||
// Numpad keys
|
|
||||||
for c := '0'; c <= '9'; c++ {
|
|
||||||
edgeKeyCodeToName[0x60+int(c-'0')] = "Numpad" + string(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const ebitengineKeysTmpl = `{{.License}}
|
const ebitengineKeysTmpl = `{{.License}}
|
||||||
|
|
||||||
{{.DoNotEdit}}
|
{{.DoNotEdit}}
|
||||||
@ -620,11 +548,6 @@ var uiKeyToJSKey = map[Key]js.Value{
|
|||||||
{{range $name, $code := .UIKeyNameToJSKey}}Key{{$name}}: js.ValueOf({{$code | printf "%q"}}),
|
{{range $name, $code := .UIKeyNameToJSKey}}Key{{$name}}: js.ValueOf({{$code | printf "%q"}}),
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
var edgeKeyCodeToUIKey = map[int]Key{
|
|
||||||
{{range $code, $name := .EdgeKeyCodeToName}}{{$code}}: Key{{$name}},
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
`
|
`
|
||||||
|
|
||||||
const glfwKeysTmpl = `{{.License}}
|
const glfwKeysTmpl = `{{.License}}
|
||||||
@ -833,7 +756,6 @@ func main() {
|
|||||||
DoNotEdit string
|
DoNotEdit string
|
||||||
BuildTag string
|
BuildTag string
|
||||||
UIKeyNameToJSKey map[string]string
|
UIKeyNameToJSKey map[string]string
|
||||||
EdgeKeyCodeToName map[int]string
|
|
||||||
EbitengineKeyNames []string
|
EbitengineKeyNames []string
|
||||||
EbitengineKeyNamesWithoutOld []string
|
EbitengineKeyNamesWithoutOld []string
|
||||||
EbitengineKeyNamesWithoutMods []string
|
EbitengineKeyNamesWithoutMods []string
|
||||||
@ -848,7 +770,6 @@ func main() {
|
|||||||
DoNotEdit: doNotEdit,
|
DoNotEdit: doNotEdit,
|
||||||
BuildTag: buildTag,
|
BuildTag: buildTag,
|
||||||
UIKeyNameToJSKey: uiKeyNameToJSKey,
|
UIKeyNameToJSKey: uiKeyNameToJSKey,
|
||||||
EdgeKeyCodeToName: edgeKeyCodeToName,
|
|
||||||
EbitengineKeyNames: ebitengineKeyNames,
|
EbitengineKeyNames: ebitengineKeyNames,
|
||||||
EbitengineKeyNamesWithoutOld: ebitengineKeyNamesWithoutOld,
|
EbitengineKeyNamesWithoutOld: ebitengineKeyNamesWithoutOld,
|
||||||
EbitengineKeyNamesWithoutMods: ebitengineKeyNamesWithoutMods,
|
EbitengineKeyNamesWithoutMods: ebitengineKeyNamesWithoutMods,
|
||||||
|
@ -57,7 +57,6 @@ type pos struct {
|
|||||||
|
|
||||||
type Input struct {
|
type Input struct {
|
||||||
keyPressed map[int]bool
|
keyPressed map[int]bool
|
||||||
keyPressedEdge map[int]bool
|
|
||||||
mouseButtonPressed map[int]bool
|
mouseButtonPressed map[int]bool
|
||||||
cursorX int
|
cursorX int
|
||||||
cursorY int
|
cursorY int
|
||||||
@ -112,16 +111,6 @@ func (i *Input) IsKeyPressed(key Key) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i.keyPressedEdge != nil {
|
|
||||||
for c, k := range edgeKeyCodeToUIKey {
|
|
||||||
if k != key {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if i.keyPressedEdge[c] {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,20 +155,6 @@ func (i *Input) keyUp(code js.Value) {
|
|||||||
i.keyPressed[jsKeyToID(code)] = false
|
i.keyPressed[jsKeyToID(code)] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Input) keyDownEdge(code int) {
|
|
||||||
if i.keyPressedEdge == nil {
|
|
||||||
i.keyPressedEdge = map[int]bool{}
|
|
||||||
}
|
|
||||||
i.keyPressedEdge[code] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) keyUpEdge(code int) {
|
|
||||||
if i.keyPressedEdge == nil {
|
|
||||||
i.keyPressedEdge = map[int]bool{}
|
|
||||||
}
|
|
||||||
i.keyPressedEdge[code] = false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) mouseDown(code int) {
|
func (i *Input) mouseDown(code int) {
|
||||||
if i.mouseButtonPressed == nil {
|
if i.mouseButtonPressed == nil {
|
||||||
i.mouseButtonPressed = map[int]bool{}
|
i.mouseButtonPressed = map[int]bool{}
|
||||||
@ -206,21 +181,9 @@ func (i *Input) updateFromEvent(e js.Value) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
i.keyDown(e.Get("code"))
|
||||||
c := e.Get("code")
|
|
||||||
if c.Type() != js.TypeString {
|
|
||||||
i.keyDownEdge(e.Get("keyCode").Int())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
i.keyDown(c)
|
|
||||||
case t.Equal(stringKeyup):
|
case t.Equal(stringKeyup):
|
||||||
c := e.Get("code")
|
i.keyUp(e.Get("code"))
|
||||||
if c.Type() != js.TypeString {
|
|
||||||
// Assume that UA is Edge.
|
|
||||||
i.keyUpEdge(e.Get("keyCode").Int())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
i.keyUp(c)
|
|
||||||
case t.Equal(stringMousedown):
|
case t.Equal(stringMousedown):
|
||||||
button := e.Get("button").Int()
|
button := e.Get("button").Int()
|
||||||
i.mouseDown(button)
|
i.mouseDown(button)
|
||||||
|
@ -127,105 +127,3 @@ var uiKeyToJSKey = map[Key]js.Value{
|
|||||||
KeyY: js.ValueOf("KeyY"),
|
KeyY: js.ValueOf("KeyY"),
|
||||||
KeyZ: js.ValueOf("KeyZ"),
|
KeyZ: js.ValueOf("KeyZ"),
|
||||||
}
|
}
|
||||||
|
|
||||||
var edgeKeyCodeToUIKey = map[int]Key{
|
|
||||||
8: KeyBackspace,
|
|
||||||
9: KeyTab,
|
|
||||||
13: KeyEnter,
|
|
||||||
16: KeyShiftLeft,
|
|
||||||
17: KeyControlLeft,
|
|
||||||
18: KeyAltLeft,
|
|
||||||
19: KeyPause,
|
|
||||||
20: KeyCapsLock,
|
|
||||||
27: KeyEscape,
|
|
||||||
32: KeySpace,
|
|
||||||
33: KeyPageUp,
|
|
||||||
34: KeyPageDown,
|
|
||||||
35: KeyEnd,
|
|
||||||
36: KeyHome,
|
|
||||||
37: KeyArrowLeft,
|
|
||||||
38: KeyArrowUp,
|
|
||||||
39: KeyArrowRight,
|
|
||||||
40: KeyArrowDown,
|
|
||||||
45: KeyInsert,
|
|
||||||
46: KeyDelete,
|
|
||||||
48: KeyDigit0,
|
|
||||||
49: KeyDigit1,
|
|
||||||
50: KeyDigit2,
|
|
||||||
51: KeyDigit3,
|
|
||||||
52: KeyDigit4,
|
|
||||||
53: KeyDigit5,
|
|
||||||
54: KeyDigit6,
|
|
||||||
55: KeyDigit7,
|
|
||||||
56: KeyDigit8,
|
|
||||||
57: KeyDigit9,
|
|
||||||
65: KeyA,
|
|
||||||
66: KeyB,
|
|
||||||
67: KeyC,
|
|
||||||
68: KeyD,
|
|
||||||
69: KeyE,
|
|
||||||
70: KeyF,
|
|
||||||
71: KeyG,
|
|
||||||
72: KeyH,
|
|
||||||
73: KeyI,
|
|
||||||
74: KeyJ,
|
|
||||||
75: KeyK,
|
|
||||||
76: KeyL,
|
|
||||||
77: KeyM,
|
|
||||||
78: KeyN,
|
|
||||||
79: KeyO,
|
|
||||||
80: KeyP,
|
|
||||||
81: KeyQ,
|
|
||||||
82: KeyR,
|
|
||||||
83: KeyS,
|
|
||||||
84: KeyT,
|
|
||||||
85: KeyU,
|
|
||||||
86: KeyV,
|
|
||||||
87: KeyW,
|
|
||||||
88: KeyX,
|
|
||||||
89: KeyY,
|
|
||||||
90: KeyZ,
|
|
||||||
91: KeyMetaLeft,
|
|
||||||
92: KeyMetaRight,
|
|
||||||
93: KeyContextMenu,
|
|
||||||
96: KeyNumpad0,
|
|
||||||
97: KeyNumpad1,
|
|
||||||
98: KeyNumpad2,
|
|
||||||
99: KeyNumpad3,
|
|
||||||
100: KeyNumpad4,
|
|
||||||
101: KeyNumpad5,
|
|
||||||
102: KeyNumpad6,
|
|
||||||
103: KeyNumpad7,
|
|
||||||
104: KeyNumpad8,
|
|
||||||
105: KeyNumpad9,
|
|
||||||
106: KeyNumpadMultiply,
|
|
||||||
107: KeyNumpadAdd,
|
|
||||||
109: KeyNumpadSubtract,
|
|
||||||
110: KeyNumpadDecimal,
|
|
||||||
111: KeyNumpadDivide,
|
|
||||||
112: KeyF1,
|
|
||||||
113: KeyF2,
|
|
||||||
114: KeyF3,
|
|
||||||
115: KeyF4,
|
|
||||||
116: KeyF5,
|
|
||||||
117: KeyF6,
|
|
||||||
118: KeyF7,
|
|
||||||
119: KeyF8,
|
|
||||||
120: KeyF9,
|
|
||||||
121: KeyF10,
|
|
||||||
122: KeyF11,
|
|
||||||
123: KeyF12,
|
|
||||||
144: KeyNumLock,
|
|
||||||
145: KeyScrollLock,
|
|
||||||
186: KeySemicolon,
|
|
||||||
187: KeyEqual,
|
|
||||||
188: KeyComma,
|
|
||||||
189: KeyMinus,
|
|
||||||
190: KeyPeriod,
|
|
||||||
191: KeySlash,
|
|
||||||
192: KeyBackquote,
|
|
||||||
219: KeyBracketLeft,
|
|
||||||
220: KeyBackslash,
|
|
||||||
221: KeyBracketRight,
|
|
||||||
222: KeyQuote,
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user