internal/driver: move the key definitions to internal/ui

Updates #1983
This commit is contained in:
Hajime Hoshi 2022-02-06 18:13:10 +09:00
parent 887a3ff749
commit 80c03792cb
15 changed files with 907 additions and 927 deletions

View File

@ -34,12 +34,12 @@ import (
var ( var (
glfwKeyNameToGLFWKey map[string]glfw.Key glfwKeyNameToGLFWKey map[string]glfw.Key
driverKeyNameToGLFWKeyName map[string]string uiKeyNameToGLFWKeyName map[string]string
androidKeyToDriverKeyName map[int]string androidKeyToUIKeyName map[int]string
gbuildKeyToDriverKeyName map[key.Code]string gbuildKeyToUIKeyName map[key.Code]string
driverKeyNameToJSKey map[string]string uiKeyNameToJSKey map[string]string
edgeKeyCodeToName map[int]string edgeKeyCodeToName map[int]string
oldEbitenKeyNameToDriverKeyName map[string]string oldEbitenKeyNameToUIKeyName map[string]string
) )
func init() { func init() {
@ -97,7 +97,7 @@ func init() {
"Last": glfw.KeyLast, "Last": glfw.KeyLast,
} }
driverKeyNameToGLFWKeyName = map[string]string{ uiKeyNameToGLFWKeyName = map[string]string{
"Space": "Space", "Space": "Space",
"Quote": "Apostrophe", "Quote": "Apostrophe",
"Comma": "Comma", "Comma": "Comma",
@ -148,7 +148,7 @@ func init() {
} }
// https://developer.android.com/reference/android/view/KeyEvent // https://developer.android.com/reference/android/view/KeyEvent
androidKeyToDriverKeyName = map[int]string{ androidKeyToUIKeyName = map[int]string{
55: "Comma", 55: "Comma",
56: "Period", 56: "Period",
57: "AltLeft", 57: "AltLeft",
@ -198,7 +198,7 @@ func init() {
118: "MetaRight", 118: "MetaRight",
} }
gbuildKeyToDriverKeyName = map[key.Code]string{ gbuildKeyToUIKeyName = map[key.Code]string{
key.CodeComma: "Comma", key.CodeComma: "Comma",
key.CodeFullStop: "Period", key.CodeFullStop: "Period",
key.CodeLeftAlt: "AltLeft", key.CodeLeftAlt: "AltLeft",
@ -245,13 +245,13 @@ func init() {
key.CodeRightGUI: "MetaRight", key.CodeRightGUI: "MetaRight",
// Missing keys: // Missing keys:
// driver.KeyPrintScreen // ui.KeyPrintScreen
// driver.KeyScrollLock // ui.KeyScrollLock
// driver.KeyMenu // ui.KeyMenu
} }
// The driver key and JS key are almost same but very slightly different (e.g., 'A' vs 'KeyA'). // The UI key and JS key are almost same but very slightly different (e.g., 'A' vs 'KeyA').
driverKeyNameToJSKey = map[string]string{ uiKeyNameToJSKey = map[string]string{
"Comma": "Comma", "Comma": "Comma",
"Period": "Period", "Period": "Period",
"AltLeft": "AltLeft", "AltLeft": "AltLeft",
@ -305,53 +305,53 @@ func init() {
for c := '0'; c <= '9'; c++ { for c := '0'; c <= '9'; c++ {
glfwKeyNameToGLFWKey[string(c)] = glfw.Key0 + glfw.Key(c) - '0' glfwKeyNameToGLFWKey[string(c)] = glfw.Key0 + glfw.Key(c) - '0'
name := "Digit" + string(c) name := "Digit" + string(c)
driverKeyNameToGLFWKeyName[name] = string(c) uiKeyNameToGLFWKeyName[name] = string(c)
androidKeyToDriverKeyName[7+int(c)-'0'] = name androidKeyToUIKeyName[7+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
// in this order. // in this order.
if c == '0' { if c == '0' {
gbuildKeyToDriverKeyName[key.Code0] = name gbuildKeyToUIKeyName[key.Code0] = name
} else { } else {
gbuildKeyToDriverKeyName[key.Code1+key.Code(c)-'1'] = name gbuildKeyToUIKeyName[key.Code1+key.Code(c)-'1'] = name
} }
driverKeyNameToJSKey[name] = name uiKeyNameToJSKey[name] = name
} }
// 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)] = glfw.KeyA + glfw.Key(c) - 'A'
driverKeyNameToGLFWKeyName[string(c)] = string(c) uiKeyNameToGLFWKeyName[string(c)] = string(c)
androidKeyToDriverKeyName[29+int(c)-'A'] = string(c) androidKeyToUIKeyName[29+int(c)-'A'] = string(c)
gbuildKeyToDriverKeyName[key.CodeA+key.Code(c)-'A'] = string(c) gbuildKeyToUIKeyName[key.CodeA+key.Code(c)-'A'] = string(c)
driverKeyNameToJSKey[string(c)] = "Key" + string(c) uiKeyNameToJSKey[string(c)] = "Key" + string(c)
} }
// 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] = glfw.KeyF1 + glfw.Key(i) - 1
driverKeyNameToGLFWKeyName[name] = name uiKeyNameToGLFWKeyName[name] = name
androidKeyToDriverKeyName[131+i-1] = name androidKeyToUIKeyName[131+i-1] = name
gbuildKeyToDriverKeyName[key.CodeF1+key.Code(i)-1] = name gbuildKeyToUIKeyName[key.CodeF1+key.Code(i)-1] = name
driverKeyNameToJSKey[name] = name uiKeyNameToJSKey[name] = name
} }
// Numpad // Numpad
// 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)] = glfw.KeyKP0 + glfw.Key(c) - '0'
driverKeyNameToGLFWKeyName[name] = "KP" + string(c) uiKeyNameToGLFWKeyName[name] = "KP" + string(c)
androidKeyToDriverKeyName[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
// in this order. // in this order.
if c == '0' { if c == '0' {
gbuildKeyToDriverKeyName[key.CodeKeypad0] = name gbuildKeyToUIKeyName[key.CodeKeypad0] = name
} else { } else {
gbuildKeyToDriverKeyName[key.CodeKeypad1+key.Code(c)-'1'] = name gbuildKeyToUIKeyName[key.CodeKeypad1+key.Code(c)-'1'] = name
} }
driverKeyNameToJSKey[name] = name uiKeyNameToJSKey[name] = name
} }
// Keys for backward compatibility // Keys for backward compatibility
oldEbitenKeyNameToDriverKeyName = map[string]string{ oldEbitenKeyNameToUIKeyName = map[string]string{
"0": "Digit0", "0": "Digit0",
"1": "Digit1", "1": "Digit1",
"2": "Digit2", "2": "Digit2",
@ -470,7 +470,7 @@ package ebiten
import ( import (
"strings" "strings"
"github.com/hajimehoshi/ebiten/v2/internal/driver" "github.com/hajimehoshi/ebiten/v2/internal/ui"
) )
// A Key represents a keyboard key. // A Key represents a keyboard key.
@ -480,16 +480,16 @@ type Key int
// Keys. // Keys.
const ( const (
{{range $index, $name := .EbitenKeyNamesWithoutMods}}Key{{$name}} Key = Key(driver.Key{{$name}}) {{range $index, $name := .EbitenKeyNamesWithoutMods}}Key{{$name}} Key = Key(ui.Key{{$name}})
{{end}} KeyAlt Key = Key(driver.KeyReserved0) {{end}} KeyAlt Key = Key(ui.KeyReserved0)
KeyControl Key = Key(driver.KeyReserved1) KeyControl Key = Key(ui.KeyReserved1)
KeyShift Key = Key(driver.KeyReserved2) KeyShift Key = Key(ui.KeyReserved2)
KeyMeta Key = Key(driver.KeyReserved3) KeyMeta Key = Key(ui.KeyReserved3)
KeyMax Key = KeyMeta KeyMax Key = KeyMeta
// Keys for backward compatibility. // Keys for backward compatibility.
// Deprecated: as of v2.1. // Deprecated: as of v2.1.
{{range $old, $new := .OldEbitenKeyNameToDriverKeyName}}Key{{$old}} Key = Key(driver.Key{{$new}}) {{range $old, $new := .OldEbitenKeyNameToUIKeyName}}Key{{$old}} Key = Key(ui.Key{{$new}})
{{end}} {{end}}
) )
@ -523,11 +523,11 @@ func keyNameToKeyCode(name string) (Key, bool) {
} }
` `
const driverKeysTmpl = `{{.License}} const uiKeysTmpl = `{{.License}}
{{.DoNotEdit}} {{.DoNotEdit}}
package driver package ui
import ( import (
"fmt" "fmt"
@ -536,7 +536,7 @@ import (
type Key int type Key int
const ( const (
{{range $index, $name := .DriverKeyNames}}Key{{$name}}{{if eq $index 0}} Key = iota{{end}} {{range $index, $name := .UIKeyNames}}Key{{$name}}{{if eq $index 0}} Key = iota{{end}}
{{end}} KeyReserved0 {{end}} KeyReserved0
KeyReserved1 KeyReserved1
KeyReserved2 KeyReserved2
@ -545,10 +545,10 @@ const (
func (k Key) String() string { func (k Key) String() string {
switch k { switch k {
{{range $index, $name := .DriverKeyNames}}case Key{{$name}}: {{range $index, $name := .UIKeyNames}}case Key{{$name}}:
return {{$name | printf "Key%s" | printf "%q"}} return {{$name | printf "Key%s" | printf "%q"}}
{{end}}} {{end}}}
panic(fmt.Sprintf("driver: invalid key: %d", k)) panic(fmt.Sprintf("ui: invalid key: %d", k))
} }
` `
@ -559,13 +559,13 @@ const eventKeysTmpl = `{{.License}}
package event package event
import ( import (
"github.com/hajimehoshi/ebiten/v2/internal/driver" "github.com/hajimehoshi/ebiten/v2/internal/ui"
) )
type Key = driver.Key type Key = ui.Key
const ( const (
{{range $index, $name := .DriverKeyNames}}Key{{$name}} = driver.Key{{$name}} {{range $index, $name := .UIKeyNames}}Key{{$name}} = ui.Key{{$name}}
{{end}} {{end}}
) )
` `
@ -579,17 +579,16 @@ const uiGLFWKeysTmpl = `{{.License}}
package ui package ui
import ( import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/glfw" "github.com/hajimehoshi/ebiten/v2/internal/glfw"
) )
var glfwKeyToDriverKey = map[glfw.Key]driver.Key{ var glfwKeyToUIKey = map[glfw.Key]Key{
{{range $dname, $gname := .DriverKeyNameToGLFWKeyName}}glfw.Key{{$gname}}: driver.Key{{$dname}}, {{range $dname, $gname := .UIKeyNameToGLFWKeyName}}glfw.Key{{$gname}}: Key{{$dname}},
{{end}} {{end}}
} }
var driverKeyToGLFWKey = map[driver.Key]glfw.Key{ var uiKeyToGLFWKey = map[Key]glfw.Key{
{{range $dname, $gname := .DriverKeyNameToGLFWKeyName}}driver.Key{{$dname}}: glfw.Key{{$gname}}, {{range $dname, $gname := .UIKeyNameToGLFWKeyName}}Key{{$dname}}: glfw.Key{{$gname}},
{{end}} {{end}}
} }
` `
@ -604,17 +603,15 @@ package ui
import ( import (
"syscall/js" "syscall/js"
"github.com/hajimehoshi/ebiten/v2/internal/driver"
) )
var driverKeyToJSKey = map[driver.Key]js.Value{ var uiKeyToJSKey = map[Key]js.Value{
{{range $name, $code := .DriverKeyNameToJSKey}}driver.Key{{$name}}: js.ValueOf({{$code | printf "%q"}}), {{range $name, $code := .UIKeyNameToJSKey}}Key{{$name}}: js.ValueOf({{$code | printf "%q"}}),
{{end}} {{end}}
} }
var edgeKeyCodeToDriverKey = map[int]driver.Key{ var edgeKeyCodeToUIKey = map[int]Key{
{{range $code, $name := .EdgeKeyCodeToName}}{{$code}}: driver.Key{{$name}}, {{range $code, $name := .EdgeKeyCodeToName}}{{$code}}: Key{{$name}},
{{end}} {{end}}
} }
` `
@ -642,11 +639,11 @@ const mobileAndroidKeysTmpl = `{{.License}}
package ebitenmobileview package ebitenmobileview
import ( import (
"github.com/hajimehoshi/ebiten/v2/internal/driver" "github.com/hajimehoshi/ebiten/v2/internal/ui"
) )
var androidKeyToDriverKey = map[int]driver.Key{ var androidKeyToUIKey = map[int]ui.Key{
{{range $key, $name := .AndroidKeyToDriverKeyName}}{{$key}}: driver.Key{{$name}}, {{range $key, $name := .AndroidKeyToUIKeyName}}{{$key}}: ui.Key{{$name}},
{{end}} {{end}}
} }
` `
@ -661,12 +658,10 @@ package ui
import ( import (
"golang.org/x/mobile/event/key" "golang.org/x/mobile/event/key"
"github.com/hajimehoshi/ebiten/v2/internal/driver"
) )
var gbuildKeyToDriverKey = map[key.Code]driver.Key{ var gbuildKeyToUIKey = map[key.Code]Key{
{{range $key, $name := .GBuildKeyToDriverKeyName}}key.{{$key}}: driver.Key{{$name}}, {{range $key, $name := .GBuildKeyToUIKeyName}}key.{{$key}}: Key{{$name}},
{{end}} {{end}}
} }
` `
@ -763,15 +758,15 @@ func main() {
ebitenKeyNames := []string{} ebitenKeyNames := []string{}
ebitenKeyNamesWithoutOld := []string{} ebitenKeyNamesWithoutOld := []string{}
ebitenKeyNamesWithoutMods := []string{} ebitenKeyNamesWithoutMods := []string{}
driverKeyNames := []string{} uiKeyNames := []string{}
for name := range driverKeyNameToJSKey { for name := range uiKeyNameToJSKey {
driverKeyNames = append(driverKeyNames, name) uiKeyNames = append(uiKeyNames, name)
ebitenKeyNames = append(ebitenKeyNames, name) ebitenKeyNames = append(ebitenKeyNames, name)
ebitenKeyNamesWithoutOld = append(ebitenKeyNamesWithoutOld, name) ebitenKeyNamesWithoutOld = append(ebitenKeyNamesWithoutOld, name)
ebitenKeyNamesWithoutMods = append(ebitenKeyNamesWithoutMods, name) ebitenKeyNamesWithoutMods = append(ebitenKeyNamesWithoutMods, name)
} }
for old := range oldEbitenKeyNameToDriverKeyName { for old := range oldEbitenKeyNameToUIKeyName {
ebitenKeyNames = append(ebitenKeyNames, old) ebitenKeyNames = append(ebitenKeyNames, old)
} }
// Keys for modifiers // Keys for modifiers
@ -781,15 +776,15 @@ func main() {
sort.Slice(ebitenKeyNames, keyNamesLess(ebitenKeyNames)) sort.Slice(ebitenKeyNames, keyNamesLess(ebitenKeyNames))
sort.Slice(ebitenKeyNamesWithoutOld, keyNamesLess(ebitenKeyNamesWithoutOld)) sort.Slice(ebitenKeyNamesWithoutOld, keyNamesLess(ebitenKeyNamesWithoutOld))
sort.Slice(ebitenKeyNamesWithoutMods, keyNamesLess(ebitenKeyNamesWithoutMods)) sort.Slice(ebitenKeyNamesWithoutMods, keyNamesLess(ebitenKeyNamesWithoutMods))
sort.Slice(driverKeyNames, keyNamesLess(driverKeyNames)) sort.Slice(uiKeyNames, keyNamesLess(uiKeyNames))
// TODO: Add this line for event package (#926). // TODO: Add this line for event package (#926).
// //
// filepath.Join("event", "keys.go"): eventKeysTmpl, // filepath.Join("event", "keys.go"): eventKeysTmpl,
for path, tmpl := range map[string]string{ for path, tmpl := range map[string]string{
filepath.Join("internal", "driver", "keys.go"): driverKeysTmpl,
filepath.Join("internal", "glfw", "keys.go"): glfwKeysTmpl, filepath.Join("internal", "glfw", "keys.go"): glfwKeysTmpl,
filepath.Join("internal", "ui", "keys.go"): uiKeysTmpl,
filepath.Join("internal", "ui", "keys_glfw.go"): uiGLFWKeysTmpl, filepath.Join("internal", "ui", "keys_glfw.go"): uiGLFWKeysTmpl,
filepath.Join("internal", "ui", "keys_mobile.go"): uiMobileKeysTmpl, filepath.Join("internal", "ui", "keys_mobile.go"): uiMobileKeysTmpl,
filepath.Join("internal", "ui", "keys_js.go"): uiJSKeysTmpl, filepath.Join("internal", "ui", "keys_js.go"): uiJSKeysTmpl,
@ -830,32 +825,32 @@ func main() {
License string License string
DoNotEdit string DoNotEdit string
BuildTag string BuildTag string
DriverKeyNameToJSKey map[string]string UIKeyNameToJSKey map[string]string
EdgeKeyCodeToName map[int]string EdgeKeyCodeToName map[int]string
EbitenKeyNames []string EbitenKeyNames []string
EbitenKeyNamesWithoutOld []string EbitenKeyNamesWithoutOld []string
EbitenKeyNamesWithoutMods []string EbitenKeyNamesWithoutMods []string
GLFWKeyNameToGLFWKey map[string]glfw.Key GLFWKeyNameToGLFWKey map[string]glfw.Key
DriverKeyNames []string UIKeyNames []string
DriverKeyNameToGLFWKeyName map[string]string UIKeyNameToGLFWKeyName map[string]string
AndroidKeyToDriverKeyName map[int]string AndroidKeyToUIKeyName map[int]string
GBuildKeyToDriverKeyName map[key.Code]string GBuildKeyToUIKeyName map[key.Code]string
OldEbitenKeyNameToDriverKeyName map[string]string OldEbitenKeyNameToUIKeyName map[string]string
}{ }{
License: license, License: license,
DoNotEdit: doNotEdit, DoNotEdit: doNotEdit,
BuildTag: buildTag, BuildTag: buildTag,
DriverKeyNameToJSKey: driverKeyNameToJSKey, UIKeyNameToJSKey: uiKeyNameToJSKey,
EdgeKeyCodeToName: edgeKeyCodeToName, EdgeKeyCodeToName: edgeKeyCodeToName,
EbitenKeyNames: ebitenKeyNames, EbitenKeyNames: ebitenKeyNames,
EbitenKeyNamesWithoutOld: ebitenKeyNamesWithoutOld, EbitenKeyNamesWithoutOld: ebitenKeyNamesWithoutOld,
EbitenKeyNamesWithoutMods: ebitenKeyNamesWithoutMods, EbitenKeyNamesWithoutMods: ebitenKeyNamesWithoutMods,
GLFWKeyNameToGLFWKey: glfwKeyNameToGLFWKey, GLFWKeyNameToGLFWKey: glfwKeyNameToGLFWKey,
DriverKeyNames: driverKeyNames, UIKeyNames: uiKeyNames,
DriverKeyNameToGLFWKeyName: driverKeyNameToGLFWKeyName, UIKeyNameToGLFWKeyName: uiKeyNameToGLFWKeyName,
AndroidKeyToDriverKeyName: androidKeyToDriverKeyName, AndroidKeyToUIKeyName: androidKeyToUIKeyName,
GBuildKeyToDriverKeyName: gbuildKeyToDriverKeyName, GBuildKeyToUIKeyName: gbuildKeyToUIKeyName,
OldEbitenKeyNameToDriverKeyName: oldEbitenKeyNameToDriverKeyName, OldEbitenKeyNameToUIKeyName: oldEbitenKeyNameToUIKeyName,
}); err != nil { }); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -15,7 +15,6 @@
package ebiten package ebiten
import ( import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/gamepad" "github.com/hajimehoshi/ebiten/v2/internal/gamepad"
"github.com/hajimehoshi/ebiten/v2/internal/gamepaddb" "github.com/hajimehoshi/ebiten/v2/internal/gamepaddb"
"github.com/hajimehoshi/ebiten/v2/internal/ui" "github.com/hajimehoshi/ebiten/v2/internal/ui"
@ -69,18 +68,18 @@ func IsKeyPressed(key Key) bool {
return false return false
} }
var keys []driver.Key var keys []ui.Key
switch key { switch key {
case KeyAlt: case KeyAlt:
keys = []driver.Key{driver.KeyAltLeft, driver.KeyAltRight} keys = []ui.Key{ui.KeyAltLeft, ui.KeyAltRight}
case KeyControl: case KeyControl:
keys = []driver.Key{driver.KeyControlLeft, driver.KeyControlRight} keys = []ui.Key{ui.KeyControlLeft, ui.KeyControlRight}
case KeyShift: case KeyShift:
keys = []driver.Key{driver.KeyShiftLeft, driver.KeyShiftRight} keys = []ui.Key{ui.KeyShiftLeft, ui.KeyShiftRight}
case KeyMeta: case KeyMeta:
keys = []driver.Key{driver.KeyMetaLeft, driver.KeyMetaRight} keys = []ui.Key{ui.KeyMetaLeft, ui.KeyMetaRight}
default: default:
keys = []driver.Key{driver.Key(key)} keys = []ui.Key{ui.Key(key)}
} }
for _, k := range keys { for _, k := range keys {
if ui.Get().Input().IsKeyPressed(k) { if ui.Get().Input().IsKeyPressed(k) {

View File

@ -21,7 +21,6 @@ import (
"sync" "sync"
"github.com/hajimehoshi/ebiten/v2/internal/cbackend" "github.com/hajimehoshi/ebiten/v2/internal/cbackend"
"github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/gamepad" "github.com/hajimehoshi/ebiten/v2/internal/gamepad"
) )
@ -66,7 +65,7 @@ func (i *Input) CursorPosition() (x, y int) {
return 0, 0 return 0, 0
} }
func (i *Input) IsKeyPressed(key driver.Key) bool { func (i *Input) IsKeyPressed(key Key) bool {
return false return false
} }

View File

@ -22,7 +22,6 @@ import (
"sync" "sync"
"unicode" "unicode"
"github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/gamepad" "github.com/hajimehoshi/ebiten/v2/internal/gamepad"
"github.com/hajimehoshi/ebiten/v2/internal/glfw" "github.com/hajimehoshi/ebiten/v2/internal/glfw"
) )
@ -104,7 +103,7 @@ func (i *Input) resetForFrame() {
i.scrollX, i.scrollY = 0, 0 i.scrollX, i.scrollY = 0, 0
} }
func (i *Input) IsKeyPressed(key driver.Key) bool { func (i *Input) IsKeyPressed(key Key) bool {
if !i.ui.isRunning() { if !i.ui.isRunning() {
return false return false
} }
@ -114,7 +113,7 @@ func (i *Input) IsKeyPressed(key driver.Key) bool {
if i.keyPressed == nil { if i.keyPressed == nil {
i.keyPressed = map[glfw.Key]bool{} i.keyPressed = map[glfw.Key]bool{}
} }
gk, ok := driverKeyToGLFWKey[key] gk, ok := uiKeyToGLFWKey[key]
return ok && i.keyPressed[gk] return ok && i.keyPressed[gk]
} }
@ -182,7 +181,7 @@ func (i *Input) update(window *glfw.Window, context Context) error {
if i.keyPressed == nil { if i.keyPressed == nil {
i.keyPressed = map[glfw.Key]bool{} i.keyPressed = map[glfw.Key]bool{}
} }
for gk := range glfwKeyToDriverKey { for gk := range glfwKeyToUIKey {
i.keyPressed[gk] = window.GetKey(gk) == glfw.Press i.keyPressed[gk] = window.GetKey(gk) == glfw.Press
} }
if i.mouseButtonPressed == nil { if i.mouseButtonPressed == nil {

View File

@ -17,8 +17,6 @@ package ui
import ( import (
"syscall/js" "syscall/js"
"unicode" "unicode"
"github.com/hajimehoshi/ebiten/v2/internal/driver"
) )
var ( var (
@ -37,7 +35,7 @@ var (
var jsKeys []js.Value var jsKeys []js.Value
func init() { func init() {
for _, k := range driverKeyToJSKey { for _, k := range uiKeyToJSKey {
jsKeys = append(jsKeys, k) jsKeys = append(jsKeys, k)
} }
} }
@ -109,14 +107,14 @@ func (i *Input) resetForFrame() {
i.wheelY = 0 i.wheelY = 0
} }
func (i *Input) IsKeyPressed(key driver.Key) bool { func (i *Input) IsKeyPressed(key Key) bool {
if i.keyPressed != nil { if i.keyPressed != nil {
if i.keyPressed[jsKeyToID(driverKeyToJSKey[key])] { if i.keyPressed[jsKeyToID(uiKeyToJSKey[key])] {
return true return true
} }
} }
if i.keyPressedEdge != nil { if i.keyPressedEdge != nil {
for c, k := range edgeKeyCodeToDriverKey { for c, k := range edgeKeyCodeToUIKey {
if k != key { if k != key {
continue continue
} }
@ -203,23 +201,23 @@ func (i *Input) updateFromEvent(e js.Value) {
c := e.Get("code") c := e.Get("code")
if c.Type() != js.TypeString { if c.Type() != js.TypeString {
code := e.Get("keyCode").Int() code := e.Get("keyCode").Int()
if edgeKeyCodeToDriverKey[code] == driver.KeyArrowUp || if edgeKeyCodeToUIKey[code] == KeyArrowUp ||
edgeKeyCodeToDriverKey[code] == driver.KeyArrowDown || edgeKeyCodeToUIKey[code] == KeyArrowDown ||
edgeKeyCodeToDriverKey[code] == driver.KeyArrowLeft || edgeKeyCodeToUIKey[code] == KeyArrowLeft ||
edgeKeyCodeToDriverKey[code] == driver.KeyArrowRight || edgeKeyCodeToUIKey[code] == KeyArrowRight ||
edgeKeyCodeToDriverKey[code] == driver.KeyBackspace || edgeKeyCodeToUIKey[code] == KeyBackspace ||
edgeKeyCodeToDriverKey[code] == driver.KeyTab { edgeKeyCodeToUIKey[code] == KeyTab {
e.Call("preventDefault") e.Call("preventDefault")
} }
i.keyDownEdge(code) i.keyDownEdge(code)
return return
} }
if c.Equal(driverKeyToJSKey[driver.KeyArrowUp]) || if c.Equal(uiKeyToJSKey[KeyArrowUp]) ||
c.Equal(driverKeyToJSKey[driver.KeyArrowDown]) || c.Equal(uiKeyToJSKey[KeyArrowDown]) ||
c.Equal(driverKeyToJSKey[driver.KeyArrowLeft]) || c.Equal(uiKeyToJSKey[KeyArrowLeft]) ||
c.Equal(driverKeyToJSKey[driver.KeyArrowRight]) || c.Equal(uiKeyToJSKey[KeyArrowRight]) ||
c.Equal(driverKeyToJSKey[driver.KeyBackspace]) || c.Equal(uiKeyToJSKey[KeyBackspace]) ||
c.Equal(driverKeyToJSKey[driver.KeyTab]) { c.Equal(uiKeyToJSKey[KeyTab]) {
e.Call("preventDefault") e.Call("preventDefault")
} }
i.keyDown(c) i.keyDown(c)

View File

@ -18,12 +18,8 @@
package ui package ui
import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
)
type Input struct { type Input struct {
keys map[driver.Key]struct{} keys map[Key]struct{}
runes []rune runes []rune
touches []Touch touches []Touch
ui *UserInterface ui *UserInterface
@ -61,7 +57,7 @@ func (i *Input) AppendInputChars(runes []rune) []rune {
return append(runes, i.runes...) return append(runes, i.runes...)
} }
func (i *Input) IsKeyPressed(key driver.Key) bool { func (i *Input) IsKeyPressed(key Key) bool {
i.ui.m.RLock() i.ui.m.RLock()
defer i.ui.m.RUnlock() defer i.ui.m.RUnlock()
@ -77,12 +73,12 @@ func (i *Input) IsMouseButtonPressed(key MouseButton) bool {
return false return false
} }
func (i *Input) update(keys map[driver.Key]struct{}, runes []rune, touches []Touch) { func (i *Input) update(keys map[Key]struct{}, runes []rune, touches []Touch) {
i.ui.m.Lock() i.ui.m.Lock()
defer i.ui.m.Unlock() defer i.ui.m.Unlock()
if i.keys == nil { if i.keys == nil {
i.keys = map[driver.Key]struct{}{} i.keys = map[Key]struct{}{}
} }
for k := range i.keys { for k := range i.keys {
delete(i.keys, k) delete(i.keys, k)

View File

@ -14,7 +14,7 @@
// Code generated by genkeys.go using 'go generate'. DO NOT EDIT. // Code generated by genkeys.go using 'go generate'. DO NOT EDIT.
package driver package ui
import ( import (
"fmt" "fmt"
@ -347,5 +347,5 @@ func (k Key) String() string {
case KeyTab: case KeyTab:
return "KeyTab" return "KeyTab"
} }
panic(fmt.Sprintf("driver: invalid key: %d", k)) panic(fmt.Sprintf("ui: invalid key: %d", k))
} }

View File

@ -20,222 +20,221 @@
package ui package ui
import ( import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/glfw" "github.com/hajimehoshi/ebiten/v2/internal/glfw"
) )
var glfwKeyToDriverKey = map[glfw.Key]driver.Key{ var glfwKeyToUIKey = map[glfw.Key]Key{
glfw.KeyA: driver.KeyA, glfw.KeyA: KeyA,
glfw.KeyLeftAlt: driver.KeyAltLeft, glfw.KeyLeftAlt: KeyAltLeft,
glfw.KeyRightAlt: driver.KeyAltRight, glfw.KeyRightAlt: KeyAltRight,
glfw.KeyDown: driver.KeyArrowDown, glfw.KeyDown: KeyArrowDown,
glfw.KeyLeft: driver.KeyArrowLeft, glfw.KeyLeft: KeyArrowLeft,
glfw.KeyRight: driver.KeyArrowRight, glfw.KeyRight: KeyArrowRight,
glfw.KeyUp: driver.KeyArrowUp, glfw.KeyUp: KeyArrowUp,
glfw.KeyB: driver.KeyB, glfw.KeyB: KeyB,
glfw.KeyGraveAccent: driver.KeyBackquote, glfw.KeyGraveAccent: KeyBackquote,
glfw.KeyBackslash: driver.KeyBackslash, glfw.KeyBackslash: KeyBackslash,
glfw.KeyBackspace: driver.KeyBackspace, glfw.KeyBackspace: KeyBackspace,
glfw.KeyLeftBracket: driver.KeyBracketLeft, glfw.KeyLeftBracket: KeyBracketLeft,
glfw.KeyRightBracket: driver.KeyBracketRight, glfw.KeyRightBracket: KeyBracketRight,
glfw.KeyC: driver.KeyC, glfw.KeyC: KeyC,
glfw.KeyCapsLock: driver.KeyCapsLock, glfw.KeyCapsLock: KeyCapsLock,
glfw.KeyComma: driver.KeyComma, glfw.KeyComma: KeyComma,
glfw.KeyMenu: driver.KeyContextMenu, glfw.KeyMenu: KeyContextMenu,
glfw.KeyLeftControl: driver.KeyControlLeft, glfw.KeyLeftControl: KeyControlLeft,
glfw.KeyRightControl: driver.KeyControlRight, glfw.KeyRightControl: KeyControlRight,
glfw.KeyD: driver.KeyD, glfw.KeyD: KeyD,
glfw.KeyDelete: driver.KeyDelete, glfw.KeyDelete: KeyDelete,
glfw.Key0: driver.KeyDigit0, glfw.Key0: KeyDigit0,
glfw.Key1: driver.KeyDigit1, glfw.Key1: KeyDigit1,
glfw.Key2: driver.KeyDigit2, glfw.Key2: KeyDigit2,
glfw.Key3: driver.KeyDigit3, glfw.Key3: KeyDigit3,
glfw.Key4: driver.KeyDigit4, glfw.Key4: KeyDigit4,
glfw.Key5: driver.KeyDigit5, glfw.Key5: KeyDigit5,
glfw.Key6: driver.KeyDigit6, glfw.Key6: KeyDigit6,
glfw.Key7: driver.KeyDigit7, glfw.Key7: KeyDigit7,
glfw.Key8: driver.KeyDigit8, glfw.Key8: KeyDigit8,
glfw.Key9: driver.KeyDigit9, glfw.Key9: KeyDigit9,
glfw.KeyE: driver.KeyE, glfw.KeyE: KeyE,
glfw.KeyEnd: driver.KeyEnd, glfw.KeyEnd: KeyEnd,
glfw.KeyEnter: driver.KeyEnter, glfw.KeyEnter: KeyEnter,
glfw.KeyEqual: driver.KeyEqual, glfw.KeyEqual: KeyEqual,
glfw.KeyEscape: driver.KeyEscape, glfw.KeyEscape: KeyEscape,
glfw.KeyF: driver.KeyF, glfw.KeyF: KeyF,
glfw.KeyF1: driver.KeyF1, glfw.KeyF1: KeyF1,
glfw.KeyF10: driver.KeyF10, glfw.KeyF10: KeyF10,
glfw.KeyF11: driver.KeyF11, glfw.KeyF11: KeyF11,
glfw.KeyF12: driver.KeyF12, glfw.KeyF12: KeyF12,
glfw.KeyF2: driver.KeyF2, glfw.KeyF2: KeyF2,
glfw.KeyF3: driver.KeyF3, glfw.KeyF3: KeyF3,
glfw.KeyF4: driver.KeyF4, glfw.KeyF4: KeyF4,
glfw.KeyF5: driver.KeyF5, glfw.KeyF5: KeyF5,
glfw.KeyF6: driver.KeyF6, glfw.KeyF6: KeyF6,
glfw.KeyF7: driver.KeyF7, glfw.KeyF7: KeyF7,
glfw.KeyF8: driver.KeyF8, glfw.KeyF8: KeyF8,
glfw.KeyF9: driver.KeyF9, glfw.KeyF9: KeyF9,
glfw.KeyG: driver.KeyG, glfw.KeyG: KeyG,
glfw.KeyH: driver.KeyH, glfw.KeyH: KeyH,
glfw.KeyHome: driver.KeyHome, glfw.KeyHome: KeyHome,
glfw.KeyI: driver.KeyI, glfw.KeyI: KeyI,
glfw.KeyInsert: driver.KeyInsert, glfw.KeyInsert: KeyInsert,
glfw.KeyJ: driver.KeyJ, glfw.KeyJ: KeyJ,
glfw.KeyK: driver.KeyK, glfw.KeyK: KeyK,
glfw.KeyL: driver.KeyL, glfw.KeyL: KeyL,
glfw.KeyM: driver.KeyM, glfw.KeyM: KeyM,
glfw.KeyLeftSuper: driver.KeyMetaLeft, glfw.KeyLeftSuper: KeyMetaLeft,
glfw.KeyRightSuper: driver.KeyMetaRight, glfw.KeyRightSuper: KeyMetaRight,
glfw.KeyMinus: driver.KeyMinus, glfw.KeyMinus: KeyMinus,
glfw.KeyN: driver.KeyN, glfw.KeyN: KeyN,
glfw.KeyNumLock: driver.KeyNumLock, glfw.KeyNumLock: KeyNumLock,
glfw.KeyKP0: driver.KeyNumpad0, glfw.KeyKP0: KeyNumpad0,
glfw.KeyKP1: driver.KeyNumpad1, glfw.KeyKP1: KeyNumpad1,
glfw.KeyKP2: driver.KeyNumpad2, glfw.KeyKP2: KeyNumpad2,
glfw.KeyKP3: driver.KeyNumpad3, glfw.KeyKP3: KeyNumpad3,
glfw.KeyKP4: driver.KeyNumpad4, glfw.KeyKP4: KeyNumpad4,
glfw.KeyKP5: driver.KeyNumpad5, glfw.KeyKP5: KeyNumpad5,
glfw.KeyKP6: driver.KeyNumpad6, glfw.KeyKP6: KeyNumpad6,
glfw.KeyKP7: driver.KeyNumpad7, glfw.KeyKP7: KeyNumpad7,
glfw.KeyKP8: driver.KeyNumpad8, glfw.KeyKP8: KeyNumpad8,
glfw.KeyKP9: driver.KeyNumpad9, glfw.KeyKP9: KeyNumpad9,
glfw.KeyKPAdd: driver.KeyNumpadAdd, glfw.KeyKPAdd: KeyNumpadAdd,
glfw.KeyKPDecimal: driver.KeyNumpadDecimal, glfw.KeyKPDecimal: KeyNumpadDecimal,
glfw.KeyKPDivide: driver.KeyNumpadDivide, glfw.KeyKPDivide: KeyNumpadDivide,
glfw.KeyKPEnter: driver.KeyNumpadEnter, glfw.KeyKPEnter: KeyNumpadEnter,
glfw.KeyKPEqual: driver.KeyNumpadEqual, glfw.KeyKPEqual: KeyNumpadEqual,
glfw.KeyKPMultiply: driver.KeyNumpadMultiply, glfw.KeyKPMultiply: KeyNumpadMultiply,
glfw.KeyKPSubtract: driver.KeyNumpadSubtract, glfw.KeyKPSubtract: KeyNumpadSubtract,
glfw.KeyO: driver.KeyO, glfw.KeyO: KeyO,
glfw.KeyP: driver.KeyP, glfw.KeyP: KeyP,
glfw.KeyPageDown: driver.KeyPageDown, glfw.KeyPageDown: KeyPageDown,
glfw.KeyPageUp: driver.KeyPageUp, glfw.KeyPageUp: KeyPageUp,
glfw.KeyPause: driver.KeyPause, glfw.KeyPause: KeyPause,
glfw.KeyPeriod: driver.KeyPeriod, glfw.KeyPeriod: KeyPeriod,
glfw.KeyPrintScreen: driver.KeyPrintScreen, glfw.KeyPrintScreen: KeyPrintScreen,
glfw.KeyQ: driver.KeyQ, glfw.KeyQ: KeyQ,
glfw.KeyApostrophe: driver.KeyQuote, glfw.KeyApostrophe: KeyQuote,
glfw.KeyR: driver.KeyR, glfw.KeyR: KeyR,
glfw.KeyS: driver.KeyS, glfw.KeyS: KeyS,
glfw.KeyScrollLock: driver.KeyScrollLock, glfw.KeyScrollLock: KeyScrollLock,
glfw.KeySemicolon: driver.KeySemicolon, glfw.KeySemicolon: KeySemicolon,
glfw.KeyLeftShift: driver.KeyShiftLeft, glfw.KeyLeftShift: KeyShiftLeft,
glfw.KeyRightShift: driver.KeyShiftRight, glfw.KeyRightShift: KeyShiftRight,
glfw.KeySlash: driver.KeySlash, glfw.KeySlash: KeySlash,
glfw.KeySpace: driver.KeySpace, glfw.KeySpace: KeySpace,
glfw.KeyT: driver.KeyT, glfw.KeyT: KeyT,
glfw.KeyTab: driver.KeyTab, glfw.KeyTab: KeyTab,
glfw.KeyU: driver.KeyU, glfw.KeyU: KeyU,
glfw.KeyV: driver.KeyV, glfw.KeyV: KeyV,
glfw.KeyW: driver.KeyW, glfw.KeyW: KeyW,
glfw.KeyX: driver.KeyX, glfw.KeyX: KeyX,
glfw.KeyY: driver.KeyY, glfw.KeyY: KeyY,
glfw.KeyZ: driver.KeyZ, glfw.KeyZ: KeyZ,
} }
var driverKeyToGLFWKey = map[driver.Key]glfw.Key{ var uiKeyToGLFWKey = map[Key]glfw.Key{
driver.KeyA: glfw.KeyA, KeyA: glfw.KeyA,
driver.KeyAltLeft: glfw.KeyLeftAlt, KeyAltLeft: glfw.KeyLeftAlt,
driver.KeyAltRight: glfw.KeyRightAlt, KeyAltRight: glfw.KeyRightAlt,
driver.KeyArrowDown: glfw.KeyDown, KeyArrowDown: glfw.KeyDown,
driver.KeyArrowLeft: glfw.KeyLeft, KeyArrowLeft: glfw.KeyLeft,
driver.KeyArrowRight: glfw.KeyRight, KeyArrowRight: glfw.KeyRight,
driver.KeyArrowUp: glfw.KeyUp, KeyArrowUp: glfw.KeyUp,
driver.KeyB: glfw.KeyB, KeyB: glfw.KeyB,
driver.KeyBackquote: glfw.KeyGraveAccent, KeyBackquote: glfw.KeyGraveAccent,
driver.KeyBackslash: glfw.KeyBackslash, KeyBackslash: glfw.KeyBackslash,
driver.KeyBackspace: glfw.KeyBackspace, KeyBackspace: glfw.KeyBackspace,
driver.KeyBracketLeft: glfw.KeyLeftBracket, KeyBracketLeft: glfw.KeyLeftBracket,
driver.KeyBracketRight: glfw.KeyRightBracket, KeyBracketRight: glfw.KeyRightBracket,
driver.KeyC: glfw.KeyC, KeyC: glfw.KeyC,
driver.KeyCapsLock: glfw.KeyCapsLock, KeyCapsLock: glfw.KeyCapsLock,
driver.KeyComma: glfw.KeyComma, KeyComma: glfw.KeyComma,
driver.KeyContextMenu: glfw.KeyMenu, KeyContextMenu: glfw.KeyMenu,
driver.KeyControlLeft: glfw.KeyLeftControl, KeyControlLeft: glfw.KeyLeftControl,
driver.KeyControlRight: glfw.KeyRightControl, KeyControlRight: glfw.KeyRightControl,
driver.KeyD: glfw.KeyD, KeyD: glfw.KeyD,
driver.KeyDelete: glfw.KeyDelete, KeyDelete: glfw.KeyDelete,
driver.KeyDigit0: glfw.Key0, KeyDigit0: glfw.Key0,
driver.KeyDigit1: glfw.Key1, KeyDigit1: glfw.Key1,
driver.KeyDigit2: glfw.Key2, KeyDigit2: glfw.Key2,
driver.KeyDigit3: glfw.Key3, KeyDigit3: glfw.Key3,
driver.KeyDigit4: glfw.Key4, KeyDigit4: glfw.Key4,
driver.KeyDigit5: glfw.Key5, KeyDigit5: glfw.Key5,
driver.KeyDigit6: glfw.Key6, KeyDigit6: glfw.Key6,
driver.KeyDigit7: glfw.Key7, KeyDigit7: glfw.Key7,
driver.KeyDigit8: glfw.Key8, KeyDigit8: glfw.Key8,
driver.KeyDigit9: glfw.Key9, KeyDigit9: glfw.Key9,
driver.KeyE: glfw.KeyE, KeyE: glfw.KeyE,
driver.KeyEnd: glfw.KeyEnd, KeyEnd: glfw.KeyEnd,
driver.KeyEnter: glfw.KeyEnter, KeyEnter: glfw.KeyEnter,
driver.KeyEqual: glfw.KeyEqual, KeyEqual: glfw.KeyEqual,
driver.KeyEscape: glfw.KeyEscape, KeyEscape: glfw.KeyEscape,
driver.KeyF: glfw.KeyF, KeyF: glfw.KeyF,
driver.KeyF1: glfw.KeyF1, KeyF1: glfw.KeyF1,
driver.KeyF10: glfw.KeyF10, KeyF10: glfw.KeyF10,
driver.KeyF11: glfw.KeyF11, KeyF11: glfw.KeyF11,
driver.KeyF12: glfw.KeyF12, KeyF12: glfw.KeyF12,
driver.KeyF2: glfw.KeyF2, KeyF2: glfw.KeyF2,
driver.KeyF3: glfw.KeyF3, KeyF3: glfw.KeyF3,
driver.KeyF4: glfw.KeyF4, KeyF4: glfw.KeyF4,
driver.KeyF5: glfw.KeyF5, KeyF5: glfw.KeyF5,
driver.KeyF6: glfw.KeyF6, KeyF6: glfw.KeyF6,
driver.KeyF7: glfw.KeyF7, KeyF7: glfw.KeyF7,
driver.KeyF8: glfw.KeyF8, KeyF8: glfw.KeyF8,
driver.KeyF9: glfw.KeyF9, KeyF9: glfw.KeyF9,
driver.KeyG: glfw.KeyG, KeyG: glfw.KeyG,
driver.KeyH: glfw.KeyH, KeyH: glfw.KeyH,
driver.KeyHome: glfw.KeyHome, KeyHome: glfw.KeyHome,
driver.KeyI: glfw.KeyI, KeyI: glfw.KeyI,
driver.KeyInsert: glfw.KeyInsert, KeyInsert: glfw.KeyInsert,
driver.KeyJ: glfw.KeyJ, KeyJ: glfw.KeyJ,
driver.KeyK: glfw.KeyK, KeyK: glfw.KeyK,
driver.KeyL: glfw.KeyL, KeyL: glfw.KeyL,
driver.KeyM: glfw.KeyM, KeyM: glfw.KeyM,
driver.KeyMetaLeft: glfw.KeyLeftSuper, KeyMetaLeft: glfw.KeyLeftSuper,
driver.KeyMetaRight: glfw.KeyRightSuper, KeyMetaRight: glfw.KeyRightSuper,
driver.KeyMinus: glfw.KeyMinus, KeyMinus: glfw.KeyMinus,
driver.KeyN: glfw.KeyN, KeyN: glfw.KeyN,
driver.KeyNumLock: glfw.KeyNumLock, KeyNumLock: glfw.KeyNumLock,
driver.KeyNumpad0: glfw.KeyKP0, KeyNumpad0: glfw.KeyKP0,
driver.KeyNumpad1: glfw.KeyKP1, KeyNumpad1: glfw.KeyKP1,
driver.KeyNumpad2: glfw.KeyKP2, KeyNumpad2: glfw.KeyKP2,
driver.KeyNumpad3: glfw.KeyKP3, KeyNumpad3: glfw.KeyKP3,
driver.KeyNumpad4: glfw.KeyKP4, KeyNumpad4: glfw.KeyKP4,
driver.KeyNumpad5: glfw.KeyKP5, KeyNumpad5: glfw.KeyKP5,
driver.KeyNumpad6: glfw.KeyKP6, KeyNumpad6: glfw.KeyKP6,
driver.KeyNumpad7: glfw.KeyKP7, KeyNumpad7: glfw.KeyKP7,
driver.KeyNumpad8: glfw.KeyKP8, KeyNumpad8: glfw.KeyKP8,
driver.KeyNumpad9: glfw.KeyKP9, KeyNumpad9: glfw.KeyKP9,
driver.KeyNumpadAdd: glfw.KeyKPAdd, KeyNumpadAdd: glfw.KeyKPAdd,
driver.KeyNumpadDecimal: glfw.KeyKPDecimal, KeyNumpadDecimal: glfw.KeyKPDecimal,
driver.KeyNumpadDivide: glfw.KeyKPDivide, KeyNumpadDivide: glfw.KeyKPDivide,
driver.KeyNumpadEnter: glfw.KeyKPEnter, KeyNumpadEnter: glfw.KeyKPEnter,
driver.KeyNumpadEqual: glfw.KeyKPEqual, KeyNumpadEqual: glfw.KeyKPEqual,
driver.KeyNumpadMultiply: glfw.KeyKPMultiply, KeyNumpadMultiply: glfw.KeyKPMultiply,
driver.KeyNumpadSubtract: glfw.KeyKPSubtract, KeyNumpadSubtract: glfw.KeyKPSubtract,
driver.KeyO: glfw.KeyO, KeyO: glfw.KeyO,
driver.KeyP: glfw.KeyP, KeyP: glfw.KeyP,
driver.KeyPageDown: glfw.KeyPageDown, KeyPageDown: glfw.KeyPageDown,
driver.KeyPageUp: glfw.KeyPageUp, KeyPageUp: glfw.KeyPageUp,
driver.KeyPause: glfw.KeyPause, KeyPause: glfw.KeyPause,
driver.KeyPeriod: glfw.KeyPeriod, KeyPeriod: glfw.KeyPeriod,
driver.KeyPrintScreen: glfw.KeyPrintScreen, KeyPrintScreen: glfw.KeyPrintScreen,
driver.KeyQ: glfw.KeyQ, KeyQ: glfw.KeyQ,
driver.KeyQuote: glfw.KeyApostrophe, KeyQuote: glfw.KeyApostrophe,
driver.KeyR: glfw.KeyR, KeyR: glfw.KeyR,
driver.KeyS: glfw.KeyS, KeyS: glfw.KeyS,
driver.KeyScrollLock: glfw.KeyScrollLock, KeyScrollLock: glfw.KeyScrollLock,
driver.KeySemicolon: glfw.KeySemicolon, KeySemicolon: glfw.KeySemicolon,
driver.KeyShiftLeft: glfw.KeyLeftShift, KeyShiftLeft: glfw.KeyLeftShift,
driver.KeyShiftRight: glfw.KeyRightShift, KeyShiftRight: glfw.KeyRightShift,
driver.KeySlash: glfw.KeySlash, KeySlash: glfw.KeySlash,
driver.KeySpace: glfw.KeySpace, KeySpace: glfw.KeySpace,
driver.KeyT: glfw.KeyT, KeyT: glfw.KeyT,
driver.KeyTab: glfw.KeyTab, KeyTab: glfw.KeyTab,
driver.KeyU: glfw.KeyU, KeyU: glfw.KeyU,
driver.KeyV: glfw.KeyV, KeyV: glfw.KeyV,
driver.KeyW: glfw.KeyW, KeyW: glfw.KeyW,
driver.KeyX: glfw.KeyX, KeyX: glfw.KeyX,
driver.KeyY: glfw.KeyY, KeyY: glfw.KeyY,
driver.KeyZ: glfw.KeyZ, KeyZ: glfw.KeyZ,
} }

View File

@ -18,216 +18,214 @@ package ui
import ( import (
"syscall/js" "syscall/js"
"github.com/hajimehoshi/ebiten/v2/internal/driver"
) )
var driverKeyToJSKey = map[driver.Key]js.Value{ var uiKeyToJSKey = map[Key]js.Value{
driver.KeyA: js.ValueOf("KeyA"), KeyA: js.ValueOf("KeyA"),
driver.KeyAltLeft: js.ValueOf("AltLeft"), KeyAltLeft: js.ValueOf("AltLeft"),
driver.KeyAltRight: js.ValueOf("AltRight"), KeyAltRight: js.ValueOf("AltRight"),
driver.KeyArrowDown: js.ValueOf("ArrowDown"), KeyArrowDown: js.ValueOf("ArrowDown"),
driver.KeyArrowLeft: js.ValueOf("ArrowLeft"), KeyArrowLeft: js.ValueOf("ArrowLeft"),
driver.KeyArrowRight: js.ValueOf("ArrowRight"), KeyArrowRight: js.ValueOf("ArrowRight"),
driver.KeyArrowUp: js.ValueOf("ArrowUp"), KeyArrowUp: js.ValueOf("ArrowUp"),
driver.KeyB: js.ValueOf("KeyB"), KeyB: js.ValueOf("KeyB"),
driver.KeyBackquote: js.ValueOf("Backquote"), KeyBackquote: js.ValueOf("Backquote"),
driver.KeyBackslash: js.ValueOf("Backslash"), KeyBackslash: js.ValueOf("Backslash"),
driver.KeyBackspace: js.ValueOf("Backspace"), KeyBackspace: js.ValueOf("Backspace"),
driver.KeyBracketLeft: js.ValueOf("BracketLeft"), KeyBracketLeft: js.ValueOf("BracketLeft"),
driver.KeyBracketRight: js.ValueOf("BracketRight"), KeyBracketRight: js.ValueOf("BracketRight"),
driver.KeyC: js.ValueOf("KeyC"), KeyC: js.ValueOf("KeyC"),
driver.KeyCapsLock: js.ValueOf("CapsLock"), KeyCapsLock: js.ValueOf("CapsLock"),
driver.KeyComma: js.ValueOf("Comma"), KeyComma: js.ValueOf("Comma"),
driver.KeyContextMenu: js.ValueOf("ContextMenu"), KeyContextMenu: js.ValueOf("ContextMenu"),
driver.KeyControlLeft: js.ValueOf("ControlLeft"), KeyControlLeft: js.ValueOf("ControlLeft"),
driver.KeyControlRight: js.ValueOf("ControlRight"), KeyControlRight: js.ValueOf("ControlRight"),
driver.KeyD: js.ValueOf("KeyD"), KeyD: js.ValueOf("KeyD"),
driver.KeyDelete: js.ValueOf("Delete"), KeyDelete: js.ValueOf("Delete"),
driver.KeyDigit0: js.ValueOf("Digit0"), KeyDigit0: js.ValueOf("Digit0"),
driver.KeyDigit1: js.ValueOf("Digit1"), KeyDigit1: js.ValueOf("Digit1"),
driver.KeyDigit2: js.ValueOf("Digit2"), KeyDigit2: js.ValueOf("Digit2"),
driver.KeyDigit3: js.ValueOf("Digit3"), KeyDigit3: js.ValueOf("Digit3"),
driver.KeyDigit4: js.ValueOf("Digit4"), KeyDigit4: js.ValueOf("Digit4"),
driver.KeyDigit5: js.ValueOf("Digit5"), KeyDigit5: js.ValueOf("Digit5"),
driver.KeyDigit6: js.ValueOf("Digit6"), KeyDigit6: js.ValueOf("Digit6"),
driver.KeyDigit7: js.ValueOf("Digit7"), KeyDigit7: js.ValueOf("Digit7"),
driver.KeyDigit8: js.ValueOf("Digit8"), KeyDigit8: js.ValueOf("Digit8"),
driver.KeyDigit9: js.ValueOf("Digit9"), KeyDigit9: js.ValueOf("Digit9"),
driver.KeyE: js.ValueOf("KeyE"), KeyE: js.ValueOf("KeyE"),
driver.KeyEnd: js.ValueOf("End"), KeyEnd: js.ValueOf("End"),
driver.KeyEnter: js.ValueOf("Enter"), KeyEnter: js.ValueOf("Enter"),
driver.KeyEqual: js.ValueOf("Equal"), KeyEqual: js.ValueOf("Equal"),
driver.KeyEscape: js.ValueOf("Escape"), KeyEscape: js.ValueOf("Escape"),
driver.KeyF: js.ValueOf("KeyF"), KeyF: js.ValueOf("KeyF"),
driver.KeyF1: js.ValueOf("F1"), KeyF1: js.ValueOf("F1"),
driver.KeyF10: js.ValueOf("F10"), KeyF10: js.ValueOf("F10"),
driver.KeyF11: js.ValueOf("F11"), KeyF11: js.ValueOf("F11"),
driver.KeyF12: js.ValueOf("F12"), KeyF12: js.ValueOf("F12"),
driver.KeyF2: js.ValueOf("F2"), KeyF2: js.ValueOf("F2"),
driver.KeyF3: js.ValueOf("F3"), KeyF3: js.ValueOf("F3"),
driver.KeyF4: js.ValueOf("F4"), KeyF4: js.ValueOf("F4"),
driver.KeyF5: js.ValueOf("F5"), KeyF5: js.ValueOf("F5"),
driver.KeyF6: js.ValueOf("F6"), KeyF6: js.ValueOf("F6"),
driver.KeyF7: js.ValueOf("F7"), KeyF7: js.ValueOf("F7"),
driver.KeyF8: js.ValueOf("F8"), KeyF8: js.ValueOf("F8"),
driver.KeyF9: js.ValueOf("F9"), KeyF9: js.ValueOf("F9"),
driver.KeyG: js.ValueOf("KeyG"), KeyG: js.ValueOf("KeyG"),
driver.KeyH: js.ValueOf("KeyH"), KeyH: js.ValueOf("KeyH"),
driver.KeyHome: js.ValueOf("Home"), KeyHome: js.ValueOf("Home"),
driver.KeyI: js.ValueOf("KeyI"), KeyI: js.ValueOf("KeyI"),
driver.KeyInsert: js.ValueOf("Insert"), KeyInsert: js.ValueOf("Insert"),
driver.KeyJ: js.ValueOf("KeyJ"), KeyJ: js.ValueOf("KeyJ"),
driver.KeyK: js.ValueOf("KeyK"), KeyK: js.ValueOf("KeyK"),
driver.KeyL: js.ValueOf("KeyL"), KeyL: js.ValueOf("KeyL"),
driver.KeyM: js.ValueOf("KeyM"), KeyM: js.ValueOf("KeyM"),
driver.KeyMetaLeft: js.ValueOf("MetaLeft"), KeyMetaLeft: js.ValueOf("MetaLeft"),
driver.KeyMetaRight: js.ValueOf("MetaRight"), KeyMetaRight: js.ValueOf("MetaRight"),
driver.KeyMinus: js.ValueOf("Minus"), KeyMinus: js.ValueOf("Minus"),
driver.KeyN: js.ValueOf("KeyN"), KeyN: js.ValueOf("KeyN"),
driver.KeyNumLock: js.ValueOf("NumLock"), KeyNumLock: js.ValueOf("NumLock"),
driver.KeyNumpad0: js.ValueOf("Numpad0"), KeyNumpad0: js.ValueOf("Numpad0"),
driver.KeyNumpad1: js.ValueOf("Numpad1"), KeyNumpad1: js.ValueOf("Numpad1"),
driver.KeyNumpad2: js.ValueOf("Numpad2"), KeyNumpad2: js.ValueOf("Numpad2"),
driver.KeyNumpad3: js.ValueOf("Numpad3"), KeyNumpad3: js.ValueOf("Numpad3"),
driver.KeyNumpad4: js.ValueOf("Numpad4"), KeyNumpad4: js.ValueOf("Numpad4"),
driver.KeyNumpad5: js.ValueOf("Numpad5"), KeyNumpad5: js.ValueOf("Numpad5"),
driver.KeyNumpad6: js.ValueOf("Numpad6"), KeyNumpad6: js.ValueOf("Numpad6"),
driver.KeyNumpad7: js.ValueOf("Numpad7"), KeyNumpad7: js.ValueOf("Numpad7"),
driver.KeyNumpad8: js.ValueOf("Numpad8"), KeyNumpad8: js.ValueOf("Numpad8"),
driver.KeyNumpad9: js.ValueOf("Numpad9"), KeyNumpad9: js.ValueOf("Numpad9"),
driver.KeyNumpadAdd: js.ValueOf("NumpadAdd"), KeyNumpadAdd: js.ValueOf("NumpadAdd"),
driver.KeyNumpadDecimal: js.ValueOf("NumpadDecimal"), KeyNumpadDecimal: js.ValueOf("NumpadDecimal"),
driver.KeyNumpadDivide: js.ValueOf("NumpadDivide"), KeyNumpadDivide: js.ValueOf("NumpadDivide"),
driver.KeyNumpadEnter: js.ValueOf("NumpadEnter"), KeyNumpadEnter: js.ValueOf("NumpadEnter"),
driver.KeyNumpadEqual: js.ValueOf("NumpadEqual"), KeyNumpadEqual: js.ValueOf("NumpadEqual"),
driver.KeyNumpadMultiply: js.ValueOf("NumpadMultiply"), KeyNumpadMultiply: js.ValueOf("NumpadMultiply"),
driver.KeyNumpadSubtract: js.ValueOf("NumpadSubtract"), KeyNumpadSubtract: js.ValueOf("NumpadSubtract"),
driver.KeyO: js.ValueOf("KeyO"), KeyO: js.ValueOf("KeyO"),
driver.KeyP: js.ValueOf("KeyP"), KeyP: js.ValueOf("KeyP"),
driver.KeyPageDown: js.ValueOf("PageDown"), KeyPageDown: js.ValueOf("PageDown"),
driver.KeyPageUp: js.ValueOf("PageUp"), KeyPageUp: js.ValueOf("PageUp"),
driver.KeyPause: js.ValueOf("Pause"), KeyPause: js.ValueOf("Pause"),
driver.KeyPeriod: js.ValueOf("Period"), KeyPeriod: js.ValueOf("Period"),
driver.KeyPrintScreen: js.ValueOf("PrintScreen"), KeyPrintScreen: js.ValueOf("PrintScreen"),
driver.KeyQ: js.ValueOf("KeyQ"), KeyQ: js.ValueOf("KeyQ"),
driver.KeyQuote: js.ValueOf("Quote"), KeyQuote: js.ValueOf("Quote"),
driver.KeyR: js.ValueOf("KeyR"), KeyR: js.ValueOf("KeyR"),
driver.KeyS: js.ValueOf("KeyS"), KeyS: js.ValueOf("KeyS"),
driver.KeyScrollLock: js.ValueOf("ScrollLock"), KeyScrollLock: js.ValueOf("ScrollLock"),
driver.KeySemicolon: js.ValueOf("Semicolon"), KeySemicolon: js.ValueOf("Semicolon"),
driver.KeyShiftLeft: js.ValueOf("ShiftLeft"), KeyShiftLeft: js.ValueOf("ShiftLeft"),
driver.KeyShiftRight: js.ValueOf("ShiftRight"), KeyShiftRight: js.ValueOf("ShiftRight"),
driver.KeySlash: js.ValueOf("Slash"), KeySlash: js.ValueOf("Slash"),
driver.KeySpace: js.ValueOf("Space"), KeySpace: js.ValueOf("Space"),
driver.KeyT: js.ValueOf("KeyT"), KeyT: js.ValueOf("KeyT"),
driver.KeyTab: js.ValueOf("Tab"), KeyTab: js.ValueOf("Tab"),
driver.KeyU: js.ValueOf("KeyU"), KeyU: js.ValueOf("KeyU"),
driver.KeyV: js.ValueOf("KeyV"), KeyV: js.ValueOf("KeyV"),
driver.KeyW: js.ValueOf("KeyW"), KeyW: js.ValueOf("KeyW"),
driver.KeyX: js.ValueOf("KeyX"), KeyX: js.ValueOf("KeyX"),
driver.KeyY: js.ValueOf("KeyY"), KeyY: js.ValueOf("KeyY"),
driver.KeyZ: js.ValueOf("KeyZ"), KeyZ: js.ValueOf("KeyZ"),
} }
var edgeKeyCodeToDriverKey = map[int]driver.Key{ var edgeKeyCodeToUIKey = map[int]Key{
8: driver.KeyBackspace, 8: KeyBackspace,
9: driver.KeyTab, 9: KeyTab,
13: driver.KeyEnter, 13: KeyEnter,
16: driver.KeyShiftLeft, 16: KeyShiftLeft,
17: driver.KeyControlLeft, 17: KeyControlLeft,
18: driver.KeyAltLeft, 18: KeyAltLeft,
19: driver.KeyPause, 19: KeyPause,
20: driver.KeyCapsLock, 20: KeyCapsLock,
27: driver.KeyEscape, 27: KeyEscape,
32: driver.KeySpace, 32: KeySpace,
33: driver.KeyPageUp, 33: KeyPageUp,
34: driver.KeyPageDown, 34: KeyPageDown,
35: driver.KeyEnd, 35: KeyEnd,
36: driver.KeyHome, 36: KeyHome,
37: driver.KeyArrowLeft, 37: KeyArrowLeft,
38: driver.KeyArrowUp, 38: KeyArrowUp,
39: driver.KeyArrowRight, 39: KeyArrowRight,
40: driver.KeyArrowDown, 40: KeyArrowDown,
45: driver.KeyInsert, 45: KeyInsert,
46: driver.KeyDelete, 46: KeyDelete,
48: driver.KeyDigit0, 48: KeyDigit0,
49: driver.KeyDigit1, 49: KeyDigit1,
50: driver.KeyDigit2, 50: KeyDigit2,
51: driver.KeyDigit3, 51: KeyDigit3,
52: driver.KeyDigit4, 52: KeyDigit4,
53: driver.KeyDigit5, 53: KeyDigit5,
54: driver.KeyDigit6, 54: KeyDigit6,
55: driver.KeyDigit7, 55: KeyDigit7,
56: driver.KeyDigit8, 56: KeyDigit8,
57: driver.KeyDigit9, 57: KeyDigit9,
65: driver.KeyA, 65: KeyA,
66: driver.KeyB, 66: KeyB,
67: driver.KeyC, 67: KeyC,
68: driver.KeyD, 68: KeyD,
69: driver.KeyE, 69: KeyE,
70: driver.KeyF, 70: KeyF,
71: driver.KeyG, 71: KeyG,
72: driver.KeyH, 72: KeyH,
73: driver.KeyI, 73: KeyI,
74: driver.KeyJ, 74: KeyJ,
75: driver.KeyK, 75: KeyK,
76: driver.KeyL, 76: KeyL,
77: driver.KeyM, 77: KeyM,
78: driver.KeyN, 78: KeyN,
79: driver.KeyO, 79: KeyO,
80: driver.KeyP, 80: KeyP,
81: driver.KeyQ, 81: KeyQ,
82: driver.KeyR, 82: KeyR,
83: driver.KeyS, 83: KeyS,
84: driver.KeyT, 84: KeyT,
85: driver.KeyU, 85: KeyU,
86: driver.KeyV, 86: KeyV,
87: driver.KeyW, 87: KeyW,
88: driver.KeyX, 88: KeyX,
89: driver.KeyY, 89: KeyY,
90: driver.KeyZ, 90: KeyZ,
91: driver.KeyMetaLeft, 91: KeyMetaLeft,
92: driver.KeyMetaRight, 92: KeyMetaRight,
93: driver.KeyContextMenu, 93: KeyContextMenu,
96: driver.KeyNumpad0, 96: KeyNumpad0,
97: driver.KeyNumpad1, 97: KeyNumpad1,
98: driver.KeyNumpad2, 98: KeyNumpad2,
99: driver.KeyNumpad3, 99: KeyNumpad3,
100: driver.KeyNumpad4, 100: KeyNumpad4,
101: driver.KeyNumpad5, 101: KeyNumpad5,
102: driver.KeyNumpad6, 102: KeyNumpad6,
103: driver.KeyNumpad7, 103: KeyNumpad7,
104: driver.KeyNumpad8, 104: KeyNumpad8,
105: driver.KeyNumpad9, 105: KeyNumpad9,
106: driver.KeyNumpadMultiply, 106: KeyNumpadMultiply,
107: driver.KeyNumpadAdd, 107: KeyNumpadAdd,
109: driver.KeyNumpadSubtract, 109: KeyNumpadSubtract,
110: driver.KeyNumpadDecimal, 110: KeyNumpadDecimal,
111: driver.KeyNumpadDivide, 111: KeyNumpadDivide,
112: driver.KeyF1, 112: KeyF1,
113: driver.KeyF2, 113: KeyF2,
114: driver.KeyF3, 114: KeyF3,
115: driver.KeyF4, 115: KeyF4,
116: driver.KeyF5, 116: KeyF5,
117: driver.KeyF6, 117: KeyF6,
118: driver.KeyF7, 118: KeyF7,
119: driver.KeyF8, 119: KeyF8,
120: driver.KeyF9, 120: KeyF9,
121: driver.KeyF10, 121: KeyF10,
122: driver.KeyF11, 122: KeyF11,
123: driver.KeyF12, 123: KeyF12,
144: driver.KeyNumLock, 144: KeyNumLock,
145: driver.KeyScrollLock, 145: KeyScrollLock,
186: driver.KeySemicolon, 186: KeySemicolon,
187: driver.KeyEqual, 187: KeyEqual,
188: driver.KeyComma, 188: KeyComma,
189: driver.KeyMinus, 189: KeyMinus,
190: driver.KeyPeriod, 190: KeyPeriod,
191: driver.KeySlash, 191: KeySlash,
192: driver.KeyBackquote, 192: KeyBackquote,
219: driver.KeyBracketLeft, 219: KeyBracketLeft,
220: driver.KeyBackslash, 220: KeyBackslash,
221: driver.KeyBracketRight, 221: KeyBracketRight,
222: driver.KeyQuote, 222: KeyQuote,
} }

View File

@ -22,111 +22,109 @@ package ui
import ( import (
"golang.org/x/mobile/event/key" "golang.org/x/mobile/event/key"
"github.com/hajimehoshi/ebiten/v2/internal/driver"
) )
var gbuildKeyToDriverKey = map[key.Code]driver.Key{ var gbuildKeyToUIKey = map[key.Code]Key{
key.CodeA: driver.KeyA, key.CodeA: KeyA,
key.CodeB: driver.KeyB, key.CodeB: KeyB,
key.CodeC: driver.KeyC, key.CodeC: KeyC,
key.CodeD: driver.KeyD, key.CodeD: KeyD,
key.CodeE: driver.KeyE, key.CodeE: KeyE,
key.CodeF: driver.KeyF, key.CodeF: KeyF,
key.CodeG: driver.KeyG, key.CodeG: KeyG,
key.CodeH: driver.KeyH, key.CodeH: KeyH,
key.CodeI: driver.KeyI, key.CodeI: KeyI,
key.CodeJ: driver.KeyJ, key.CodeJ: KeyJ,
key.CodeK: driver.KeyK, key.CodeK: KeyK,
key.CodeL: driver.KeyL, key.CodeL: KeyL,
key.CodeM: driver.KeyM, key.CodeM: KeyM,
key.CodeN: driver.KeyN, key.CodeN: KeyN,
key.CodeO: driver.KeyO, key.CodeO: KeyO,
key.CodeP: driver.KeyP, key.CodeP: KeyP,
key.CodeQ: driver.KeyQ, key.CodeQ: KeyQ,
key.CodeR: driver.KeyR, key.CodeR: KeyR,
key.CodeS: driver.KeyS, key.CodeS: KeyS,
key.CodeT: driver.KeyT, key.CodeT: KeyT,
key.CodeU: driver.KeyU, key.CodeU: KeyU,
key.CodeV: driver.KeyV, key.CodeV: KeyV,
key.CodeW: driver.KeyW, key.CodeW: KeyW,
key.CodeX: driver.KeyX, key.CodeX: KeyX,
key.CodeY: driver.KeyY, key.CodeY: KeyY,
key.CodeZ: driver.KeyZ, key.CodeZ: KeyZ,
key.Code1: driver.KeyDigit1, key.Code1: KeyDigit1,
key.Code2: driver.KeyDigit2, key.Code2: KeyDigit2,
key.Code3: driver.KeyDigit3, key.Code3: KeyDigit3,
key.Code4: driver.KeyDigit4, key.Code4: KeyDigit4,
key.Code5: driver.KeyDigit5, key.Code5: KeyDigit5,
key.Code6: driver.KeyDigit6, key.Code6: KeyDigit6,
key.Code7: driver.KeyDigit7, key.Code7: KeyDigit7,
key.Code8: driver.KeyDigit8, key.Code8: KeyDigit8,
key.Code9: driver.KeyDigit9, key.Code9: KeyDigit9,
key.Code0: driver.KeyDigit0, key.Code0: KeyDigit0,
key.CodeReturnEnter: driver.KeyEnter, key.CodeReturnEnter: KeyEnter,
key.CodeEscape: driver.KeyEscape, key.CodeEscape: KeyEscape,
key.CodeDeleteBackspace: driver.KeyBackspace, key.CodeDeleteBackspace: KeyBackspace,
key.CodeTab: driver.KeyTab, key.CodeTab: KeyTab,
key.CodeSpacebar: driver.KeySpace, key.CodeSpacebar: KeySpace,
key.CodeHyphenMinus: driver.KeyMinus, key.CodeHyphenMinus: KeyMinus,
key.CodeEqualSign: driver.KeyEqual, key.CodeEqualSign: KeyEqual,
key.CodeLeftSquareBracket: driver.KeyBracketLeft, key.CodeLeftSquareBracket: KeyBracketLeft,
key.CodeRightSquareBracket: driver.KeyBracketRight, key.CodeRightSquareBracket: KeyBracketRight,
key.CodeBackslash: driver.KeyBackslash, key.CodeBackslash: KeyBackslash,
key.CodeSemicolon: driver.KeySemicolon, key.CodeSemicolon: KeySemicolon,
key.CodeApostrophe: driver.KeyQuote, key.CodeApostrophe: KeyQuote,
key.CodeGraveAccent: driver.KeyBackquote, key.CodeGraveAccent: KeyBackquote,
key.CodeComma: driver.KeyComma, key.CodeComma: KeyComma,
key.CodeFullStop: driver.KeyPeriod, key.CodeFullStop: KeyPeriod,
key.CodeSlash: driver.KeySlash, key.CodeSlash: KeySlash,
key.CodeCapsLock: driver.KeyCapsLock, key.CodeCapsLock: KeyCapsLock,
key.CodeF1: driver.KeyF1, key.CodeF1: KeyF1,
key.CodeF2: driver.KeyF2, key.CodeF2: KeyF2,
key.CodeF3: driver.KeyF3, key.CodeF3: KeyF3,
key.CodeF4: driver.KeyF4, key.CodeF4: KeyF4,
key.CodeF5: driver.KeyF5, key.CodeF5: KeyF5,
key.CodeF6: driver.KeyF6, key.CodeF6: KeyF6,
key.CodeF7: driver.KeyF7, key.CodeF7: KeyF7,
key.CodeF8: driver.KeyF8, key.CodeF8: KeyF8,
key.CodeF9: driver.KeyF9, key.CodeF9: KeyF9,
key.CodeF10: driver.KeyF10, key.CodeF10: KeyF10,
key.CodeF11: driver.KeyF11, key.CodeF11: KeyF11,
key.CodeF12: driver.KeyF12, key.CodeF12: KeyF12,
key.CodePause: driver.KeyPause, key.CodePause: KeyPause,
key.CodeInsert: driver.KeyInsert, key.CodeInsert: KeyInsert,
key.CodeHome: driver.KeyHome, key.CodeHome: KeyHome,
key.CodePageUp: driver.KeyPageUp, key.CodePageUp: KeyPageUp,
key.CodeDeleteForward: driver.KeyDelete, key.CodeDeleteForward: KeyDelete,
key.CodeEnd: driver.KeyEnd, key.CodeEnd: KeyEnd,
key.CodePageDown: driver.KeyPageDown, key.CodePageDown: KeyPageDown,
key.CodeRightArrow: driver.KeyArrowRight, key.CodeRightArrow: KeyArrowRight,
key.CodeLeftArrow: driver.KeyArrowLeft, key.CodeLeftArrow: KeyArrowLeft,
key.CodeDownArrow: driver.KeyArrowDown, key.CodeDownArrow: KeyArrowDown,
key.CodeUpArrow: driver.KeyArrowUp, key.CodeUpArrow: KeyArrowUp,
key.CodeKeypadNumLock: driver.KeyNumLock, key.CodeKeypadNumLock: KeyNumLock,
key.CodeKeypadSlash: driver.KeyNumpadDivide, key.CodeKeypadSlash: KeyNumpadDivide,
key.CodeKeypadAsterisk: driver.KeyNumpadMultiply, key.CodeKeypadAsterisk: KeyNumpadMultiply,
key.CodeKeypadHyphenMinus: driver.KeyNumpadSubtract, key.CodeKeypadHyphenMinus: KeyNumpadSubtract,
key.CodeKeypadPlusSign: driver.KeyNumpadAdd, key.CodeKeypadPlusSign: KeyNumpadAdd,
key.CodeKeypadEnter: driver.KeyNumpadEnter, key.CodeKeypadEnter: KeyNumpadEnter,
key.CodeKeypad1: driver.KeyNumpad1, key.CodeKeypad1: KeyNumpad1,
key.CodeKeypad2: driver.KeyNumpad2, key.CodeKeypad2: KeyNumpad2,
key.CodeKeypad3: driver.KeyNumpad3, key.CodeKeypad3: KeyNumpad3,
key.CodeKeypad4: driver.KeyNumpad4, key.CodeKeypad4: KeyNumpad4,
key.CodeKeypad5: driver.KeyNumpad5, key.CodeKeypad5: KeyNumpad5,
key.CodeKeypad6: driver.KeyNumpad6, key.CodeKeypad6: KeyNumpad6,
key.CodeKeypad7: driver.KeyNumpad7, key.CodeKeypad7: KeyNumpad7,
key.CodeKeypad8: driver.KeyNumpad8, key.CodeKeypad8: KeyNumpad8,
key.CodeKeypad9: driver.KeyNumpad9, key.CodeKeypad9: KeyNumpad9,
key.CodeKeypad0: driver.KeyNumpad0, key.CodeKeypad0: KeyNumpad0,
key.CodeKeypadFullStop: driver.KeyNumpadDecimal, key.CodeKeypadFullStop: KeyNumpadDecimal,
key.CodeKeypadEqualSign: driver.KeyNumpadEqual, key.CodeKeypadEqualSign: KeyNumpadEqual,
key.CodeLeftControl: driver.KeyControlLeft, key.CodeLeftControl: KeyControlLeft,
key.CodeLeftShift: driver.KeyShiftLeft, key.CodeLeftShift: KeyShiftLeft,
key.CodeLeftAlt: driver.KeyAltLeft, key.CodeLeftAlt: KeyAltLeft,
key.CodeLeftGUI: driver.KeyMetaLeft, key.CodeLeftGUI: KeyMetaLeft,
key.CodeRightControl: driver.KeyControlRight, key.CodeRightControl: KeyControlRight,
key.CodeRightShift: driver.KeyShiftRight, key.CodeRightShift: KeyShiftRight,
key.CodeRightAlt: driver.KeyAltRight, key.CodeRightAlt: KeyAltRight,
key.CodeRightGUI: driver.KeyMetaRight, key.CodeRightGUI: KeyMetaRight,
} }

View File

@ -132,7 +132,7 @@ func (u *UserInterface) appMain(a app.App) {
var sizeInited bool var sizeInited bool
touches := map[touch.Sequence]Touch{} touches := map[touch.Sequence]Touch{}
keys := map[driver.Key]struct{}{} keys := map[Key]struct{}{}
for e := range a.Events() { for e := range a.Events() {
var updateInput bool var updateInput bool
@ -196,7 +196,7 @@ func (u *UserInterface) appMain(a app.App) {
} }
updateInput = true updateInput = true
case key.Event: case key.Event:
k, ok := gbuildKeyToDriverKey[e.Code] k, ok := gbuildKeyToUIKey[e.Code]
if ok { if ok {
switch e.Direction { switch e.Direction {
case key.DirPress, key.DirNone: case key.DirPress, key.DirNone:
@ -460,7 +460,7 @@ type Touch struct {
Y int Y int
} }
func (u *UserInterface) UpdateInput(keys map[driver.Key]struct{}, runes []rune, touches []Touch) { func (u *UserInterface) UpdateInput(keys map[Key]struct{}, runes []rune, touches []Touch) {
u.input.update(keys, runes, touches) u.input.update(keys, runes, touches)
if u.fpsMode == FPSModeVsyncOffMinimum { if u.fpsMode == FPSModeVsyncOffMinimum {
u.renderRequester.RequestRenderIfNeeded() u.renderRequester.RequestRenderIfNeeded()

290
keys.go
View File

@ -19,7 +19,7 @@ package ebiten
import ( import (
"strings" "strings"
"github.com/hajimehoshi/ebiten/v2/internal/driver" "github.com/hajimehoshi/ebiten/v2/internal/ui"
) )
// A Key represents a keyboard key. // A Key represents a keyboard key.
@ -29,154 +29,154 @@ type Key int
// Keys. // Keys.
const ( const (
KeyA Key = Key(driver.KeyA) KeyA Key = Key(ui.KeyA)
KeyB Key = Key(driver.KeyB) KeyB Key = Key(ui.KeyB)
KeyC Key = Key(driver.KeyC) KeyC Key = Key(ui.KeyC)
KeyD Key = Key(driver.KeyD) KeyD Key = Key(ui.KeyD)
KeyE Key = Key(driver.KeyE) KeyE Key = Key(ui.KeyE)
KeyF Key = Key(driver.KeyF) KeyF Key = Key(ui.KeyF)
KeyG Key = Key(driver.KeyG) KeyG Key = Key(ui.KeyG)
KeyH Key = Key(driver.KeyH) KeyH Key = Key(ui.KeyH)
KeyI Key = Key(driver.KeyI) KeyI Key = Key(ui.KeyI)
KeyJ Key = Key(driver.KeyJ) KeyJ Key = Key(ui.KeyJ)
KeyK Key = Key(driver.KeyK) KeyK Key = Key(ui.KeyK)
KeyL Key = Key(driver.KeyL) KeyL Key = Key(ui.KeyL)
KeyM Key = Key(driver.KeyM) KeyM Key = Key(ui.KeyM)
KeyN Key = Key(driver.KeyN) KeyN Key = Key(ui.KeyN)
KeyO Key = Key(driver.KeyO) KeyO Key = Key(ui.KeyO)
KeyP Key = Key(driver.KeyP) KeyP Key = Key(ui.KeyP)
KeyQ Key = Key(driver.KeyQ) KeyQ Key = Key(ui.KeyQ)
KeyR Key = Key(driver.KeyR) KeyR Key = Key(ui.KeyR)
KeyS Key = Key(driver.KeyS) KeyS Key = Key(ui.KeyS)
KeyT Key = Key(driver.KeyT) KeyT Key = Key(ui.KeyT)
KeyU Key = Key(driver.KeyU) KeyU Key = Key(ui.KeyU)
KeyV Key = Key(driver.KeyV) KeyV Key = Key(ui.KeyV)
KeyW Key = Key(driver.KeyW) KeyW Key = Key(ui.KeyW)
KeyX Key = Key(driver.KeyX) KeyX Key = Key(ui.KeyX)
KeyY Key = Key(driver.KeyY) KeyY Key = Key(ui.KeyY)
KeyZ Key = Key(driver.KeyZ) KeyZ Key = Key(ui.KeyZ)
KeyAltLeft Key = Key(driver.KeyAltLeft) KeyAltLeft Key = Key(ui.KeyAltLeft)
KeyAltRight Key = Key(driver.KeyAltRight) KeyAltRight Key = Key(ui.KeyAltRight)
KeyArrowDown Key = Key(driver.KeyArrowDown) KeyArrowDown Key = Key(ui.KeyArrowDown)
KeyArrowLeft Key = Key(driver.KeyArrowLeft) KeyArrowLeft Key = Key(ui.KeyArrowLeft)
KeyArrowRight Key = Key(driver.KeyArrowRight) KeyArrowRight Key = Key(ui.KeyArrowRight)
KeyArrowUp Key = Key(driver.KeyArrowUp) KeyArrowUp Key = Key(ui.KeyArrowUp)
KeyBackquote Key = Key(driver.KeyBackquote) KeyBackquote Key = Key(ui.KeyBackquote)
KeyBackslash Key = Key(driver.KeyBackslash) KeyBackslash Key = Key(ui.KeyBackslash)
KeyBackspace Key = Key(driver.KeyBackspace) KeyBackspace Key = Key(ui.KeyBackspace)
KeyBracketLeft Key = Key(driver.KeyBracketLeft) KeyBracketLeft Key = Key(ui.KeyBracketLeft)
KeyBracketRight Key = Key(driver.KeyBracketRight) KeyBracketRight Key = Key(ui.KeyBracketRight)
KeyCapsLock Key = Key(driver.KeyCapsLock) KeyCapsLock Key = Key(ui.KeyCapsLock)
KeyComma Key = Key(driver.KeyComma) KeyComma Key = Key(ui.KeyComma)
KeyContextMenu Key = Key(driver.KeyContextMenu) KeyContextMenu Key = Key(ui.KeyContextMenu)
KeyControlLeft Key = Key(driver.KeyControlLeft) KeyControlLeft Key = Key(ui.KeyControlLeft)
KeyControlRight Key = Key(driver.KeyControlRight) KeyControlRight Key = Key(ui.KeyControlRight)
KeyDelete Key = Key(driver.KeyDelete) KeyDelete Key = Key(ui.KeyDelete)
KeyDigit0 Key = Key(driver.KeyDigit0) KeyDigit0 Key = Key(ui.KeyDigit0)
KeyDigit1 Key = Key(driver.KeyDigit1) KeyDigit1 Key = Key(ui.KeyDigit1)
KeyDigit2 Key = Key(driver.KeyDigit2) KeyDigit2 Key = Key(ui.KeyDigit2)
KeyDigit3 Key = Key(driver.KeyDigit3) KeyDigit3 Key = Key(ui.KeyDigit3)
KeyDigit4 Key = Key(driver.KeyDigit4) KeyDigit4 Key = Key(ui.KeyDigit4)
KeyDigit5 Key = Key(driver.KeyDigit5) KeyDigit5 Key = Key(ui.KeyDigit5)
KeyDigit6 Key = Key(driver.KeyDigit6) KeyDigit6 Key = Key(ui.KeyDigit6)
KeyDigit7 Key = Key(driver.KeyDigit7) KeyDigit7 Key = Key(ui.KeyDigit7)
KeyDigit8 Key = Key(driver.KeyDigit8) KeyDigit8 Key = Key(ui.KeyDigit8)
KeyDigit9 Key = Key(driver.KeyDigit9) KeyDigit9 Key = Key(ui.KeyDigit9)
KeyEnd Key = Key(driver.KeyEnd) KeyEnd Key = Key(ui.KeyEnd)
KeyEnter Key = Key(driver.KeyEnter) KeyEnter Key = Key(ui.KeyEnter)
KeyEqual Key = Key(driver.KeyEqual) KeyEqual Key = Key(ui.KeyEqual)
KeyEscape Key = Key(driver.KeyEscape) KeyEscape Key = Key(ui.KeyEscape)
KeyF1 Key = Key(driver.KeyF1) KeyF1 Key = Key(ui.KeyF1)
KeyF2 Key = Key(driver.KeyF2) KeyF2 Key = Key(ui.KeyF2)
KeyF3 Key = Key(driver.KeyF3) KeyF3 Key = Key(ui.KeyF3)
KeyF4 Key = Key(driver.KeyF4) KeyF4 Key = Key(ui.KeyF4)
KeyF5 Key = Key(driver.KeyF5) KeyF5 Key = Key(ui.KeyF5)
KeyF6 Key = Key(driver.KeyF6) KeyF6 Key = Key(ui.KeyF6)
KeyF7 Key = Key(driver.KeyF7) KeyF7 Key = Key(ui.KeyF7)
KeyF8 Key = Key(driver.KeyF8) KeyF8 Key = Key(ui.KeyF8)
KeyF9 Key = Key(driver.KeyF9) KeyF9 Key = Key(ui.KeyF9)
KeyF10 Key = Key(driver.KeyF10) KeyF10 Key = Key(ui.KeyF10)
KeyF11 Key = Key(driver.KeyF11) KeyF11 Key = Key(ui.KeyF11)
KeyF12 Key = Key(driver.KeyF12) KeyF12 Key = Key(ui.KeyF12)
KeyHome Key = Key(driver.KeyHome) KeyHome Key = Key(ui.KeyHome)
KeyInsert Key = Key(driver.KeyInsert) KeyInsert Key = Key(ui.KeyInsert)
KeyMetaLeft Key = Key(driver.KeyMetaLeft) KeyMetaLeft Key = Key(ui.KeyMetaLeft)
KeyMetaRight Key = Key(driver.KeyMetaRight) KeyMetaRight Key = Key(ui.KeyMetaRight)
KeyMinus Key = Key(driver.KeyMinus) KeyMinus Key = Key(ui.KeyMinus)
KeyNumLock Key = Key(driver.KeyNumLock) KeyNumLock Key = Key(ui.KeyNumLock)
KeyNumpad0 Key = Key(driver.KeyNumpad0) KeyNumpad0 Key = Key(ui.KeyNumpad0)
KeyNumpad1 Key = Key(driver.KeyNumpad1) KeyNumpad1 Key = Key(ui.KeyNumpad1)
KeyNumpad2 Key = Key(driver.KeyNumpad2) KeyNumpad2 Key = Key(ui.KeyNumpad2)
KeyNumpad3 Key = Key(driver.KeyNumpad3) KeyNumpad3 Key = Key(ui.KeyNumpad3)
KeyNumpad4 Key = Key(driver.KeyNumpad4) KeyNumpad4 Key = Key(ui.KeyNumpad4)
KeyNumpad5 Key = Key(driver.KeyNumpad5) KeyNumpad5 Key = Key(ui.KeyNumpad5)
KeyNumpad6 Key = Key(driver.KeyNumpad6) KeyNumpad6 Key = Key(ui.KeyNumpad6)
KeyNumpad7 Key = Key(driver.KeyNumpad7) KeyNumpad7 Key = Key(ui.KeyNumpad7)
KeyNumpad8 Key = Key(driver.KeyNumpad8) KeyNumpad8 Key = Key(ui.KeyNumpad8)
KeyNumpad9 Key = Key(driver.KeyNumpad9) KeyNumpad9 Key = Key(ui.KeyNumpad9)
KeyNumpadAdd Key = Key(driver.KeyNumpadAdd) KeyNumpadAdd Key = Key(ui.KeyNumpadAdd)
KeyNumpadDecimal Key = Key(driver.KeyNumpadDecimal) KeyNumpadDecimal Key = Key(ui.KeyNumpadDecimal)
KeyNumpadDivide Key = Key(driver.KeyNumpadDivide) KeyNumpadDivide Key = Key(ui.KeyNumpadDivide)
KeyNumpadEnter Key = Key(driver.KeyNumpadEnter) KeyNumpadEnter Key = Key(ui.KeyNumpadEnter)
KeyNumpadEqual Key = Key(driver.KeyNumpadEqual) KeyNumpadEqual Key = Key(ui.KeyNumpadEqual)
KeyNumpadMultiply Key = Key(driver.KeyNumpadMultiply) KeyNumpadMultiply Key = Key(ui.KeyNumpadMultiply)
KeyNumpadSubtract Key = Key(driver.KeyNumpadSubtract) KeyNumpadSubtract Key = Key(ui.KeyNumpadSubtract)
KeyPageDown Key = Key(driver.KeyPageDown) KeyPageDown Key = Key(ui.KeyPageDown)
KeyPageUp Key = Key(driver.KeyPageUp) KeyPageUp Key = Key(ui.KeyPageUp)
KeyPause Key = Key(driver.KeyPause) KeyPause Key = Key(ui.KeyPause)
KeyPeriod Key = Key(driver.KeyPeriod) KeyPeriod Key = Key(ui.KeyPeriod)
KeyPrintScreen Key = Key(driver.KeyPrintScreen) KeyPrintScreen Key = Key(ui.KeyPrintScreen)
KeyQuote Key = Key(driver.KeyQuote) KeyQuote Key = Key(ui.KeyQuote)
KeyScrollLock Key = Key(driver.KeyScrollLock) KeyScrollLock Key = Key(ui.KeyScrollLock)
KeySemicolon Key = Key(driver.KeySemicolon) KeySemicolon Key = Key(ui.KeySemicolon)
KeyShiftLeft Key = Key(driver.KeyShiftLeft) KeyShiftLeft Key = Key(ui.KeyShiftLeft)
KeyShiftRight Key = Key(driver.KeyShiftRight) KeyShiftRight Key = Key(ui.KeyShiftRight)
KeySlash Key = Key(driver.KeySlash) KeySlash Key = Key(ui.KeySlash)
KeySpace Key = Key(driver.KeySpace) KeySpace Key = Key(ui.KeySpace)
KeyTab Key = Key(driver.KeyTab) KeyTab Key = Key(ui.KeyTab)
KeyAlt Key = Key(driver.KeyReserved0) KeyAlt Key = Key(ui.KeyReserved0)
KeyControl Key = Key(driver.KeyReserved1) KeyControl Key = Key(ui.KeyReserved1)
KeyShift Key = Key(driver.KeyReserved2) KeyShift Key = Key(ui.KeyReserved2)
KeyMeta Key = Key(driver.KeyReserved3) KeyMeta Key = Key(ui.KeyReserved3)
KeyMax Key = KeyMeta KeyMax Key = KeyMeta
// Keys for backward compatibility. // Keys for backward compatibility.
// Deprecated: as of v2.1. // Deprecated: as of v2.1.
Key0 Key = Key(driver.KeyDigit0) Key0 Key = Key(ui.KeyDigit0)
Key1 Key = Key(driver.KeyDigit1) Key1 Key = Key(ui.KeyDigit1)
Key2 Key = Key(driver.KeyDigit2) Key2 Key = Key(ui.KeyDigit2)
Key3 Key = Key(driver.KeyDigit3) Key3 Key = Key(ui.KeyDigit3)
Key4 Key = Key(driver.KeyDigit4) Key4 Key = Key(ui.KeyDigit4)
Key5 Key = Key(driver.KeyDigit5) Key5 Key = Key(ui.KeyDigit5)
Key6 Key = Key(driver.KeyDigit6) Key6 Key = Key(ui.KeyDigit6)
Key7 Key = Key(driver.KeyDigit7) Key7 Key = Key(ui.KeyDigit7)
Key8 Key = Key(driver.KeyDigit8) Key8 Key = Key(ui.KeyDigit8)
Key9 Key = Key(driver.KeyDigit9) Key9 Key = Key(ui.KeyDigit9)
KeyApostrophe Key = Key(driver.KeyQuote) KeyApostrophe Key = Key(ui.KeyQuote)
KeyDown Key = Key(driver.KeyArrowDown) KeyDown Key = Key(ui.KeyArrowDown)
KeyGraveAccent Key = Key(driver.KeyBackquote) KeyGraveAccent Key = Key(ui.KeyBackquote)
KeyKP0 Key = Key(driver.KeyNumpad0) KeyKP0 Key = Key(ui.KeyNumpad0)
KeyKP1 Key = Key(driver.KeyNumpad1) KeyKP1 Key = Key(ui.KeyNumpad1)
KeyKP2 Key = Key(driver.KeyNumpad2) KeyKP2 Key = Key(ui.KeyNumpad2)
KeyKP3 Key = Key(driver.KeyNumpad3) KeyKP3 Key = Key(ui.KeyNumpad3)
KeyKP4 Key = Key(driver.KeyNumpad4) KeyKP4 Key = Key(ui.KeyNumpad4)
KeyKP5 Key = Key(driver.KeyNumpad5) KeyKP5 Key = Key(ui.KeyNumpad5)
KeyKP6 Key = Key(driver.KeyNumpad6) KeyKP6 Key = Key(ui.KeyNumpad6)
KeyKP7 Key = Key(driver.KeyNumpad7) KeyKP7 Key = Key(ui.KeyNumpad7)
KeyKP8 Key = Key(driver.KeyNumpad8) KeyKP8 Key = Key(ui.KeyNumpad8)
KeyKP9 Key = Key(driver.KeyNumpad9) KeyKP9 Key = Key(ui.KeyNumpad9)
KeyKPDecimal Key = Key(driver.KeyNumpadDecimal) KeyKPDecimal Key = Key(ui.KeyNumpadDecimal)
KeyKPDivide Key = Key(driver.KeyNumpadDivide) KeyKPDivide Key = Key(ui.KeyNumpadDivide)
KeyKPEnter Key = Key(driver.KeyNumpadEnter) KeyKPEnter Key = Key(ui.KeyNumpadEnter)
KeyKPEqual Key = Key(driver.KeyNumpadEqual) KeyKPEqual Key = Key(ui.KeyNumpadEqual)
KeyKPMultiply Key = Key(driver.KeyNumpadMultiply) KeyKPMultiply Key = Key(ui.KeyNumpadMultiply)
KeyKPSubtract Key = Key(driver.KeyNumpadSubtract) KeyKPSubtract Key = Key(ui.KeyNumpadSubtract)
KeyLeft Key = Key(driver.KeyArrowLeft) KeyLeft Key = Key(ui.KeyArrowLeft)
KeyLeftBracket Key = Key(driver.KeyBracketLeft) KeyLeftBracket Key = Key(ui.KeyBracketLeft)
KeyMenu Key = Key(driver.KeyContextMenu) KeyMenu Key = Key(ui.KeyContextMenu)
KeyRight Key = Key(driver.KeyArrowRight) KeyRight Key = Key(ui.KeyArrowRight)
KeyRightBracket Key = Key(driver.KeyBracketRight) KeyRightBracket Key = Key(ui.KeyBracketRight)
KeyUp Key = Key(driver.KeyArrowUp) KeyUp Key = Key(ui.KeyArrowUp)
) )
func (k Key) isValid() bool { func (k Key) isValid() bool {

View File

@ -18,7 +18,6 @@
package ebitenmobileview package ebitenmobileview
import ( import (
"github.com/hajimehoshi/ebiten/v2/internal/driver"
"github.com/hajimehoshi/ebiten/v2/internal/ui" "github.com/hajimehoshi/ebiten/v2/internal/ui"
) )
@ -28,7 +27,7 @@ type position struct {
} }
var ( var (
keys = map[driver.Key]struct{}{} keys = map[ui.Key]struct{}{}
runes []rune runes []rune
touches = map[ui.TouchID]position{} touches = map[ui.TouchID]position{}
) )

View File

@ -201,7 +201,7 @@ func OnKeyDownOnAndroid(keyCode int, unicodeChar int, source int, deviceID int)
case source&sourceJoystick == sourceJoystick: case source&sourceJoystick == sourceJoystick:
// DPAD keys can come here, but they are also treated as an axis at a motion event. Ignore them. // DPAD keys can come here, but they are also treated as an axis at a motion event. Ignore them.
case source&sourceKeyboard == sourceKeyboard: case source&sourceKeyboard == sourceKeyboard:
if key, ok := androidKeyToDriverKey[keyCode]; ok { if key, ok := androidKeyToUIKey[keyCode]; ok {
keys[key] = struct{}{} keys[key] = struct{}{}
if r := rune(unicodeChar); r != 0 && unicode.IsPrint(r) { if r := rune(unicodeChar); r != 0 && unicode.IsPrint(r) {
runes = []rune{r} runes = []rune{r}
@ -221,7 +221,7 @@ func OnKeyUpOnAndroid(keyCode int, source int, deviceID int) {
case source&sourceJoystick == sourceJoystick: case source&sourceJoystick == sourceJoystick:
// DPAD keys can come here, but they are also treated as an axis at a motion event. Ignore them. // DPAD keys can come here, but they are also treated as an axis at a motion event. Ignore them.
case source&sourceKeyboard == sourceKeyboard: case source&sourceKeyboard == sourceKeyboard:
if key, ok := androidKeyToDriverKey[keyCode]; ok { if key, ok := androidKeyToUIKey[keyCode]; ok {
delete(keys, key) delete(keys, key)
updateInput() updateInput()
} }

View File

@ -17,113 +17,113 @@
package ebitenmobileview package ebitenmobileview
import ( import (
"github.com/hajimehoshi/ebiten/v2/internal/driver" "github.com/hajimehoshi/ebiten/v2/internal/ui"
) )
var androidKeyToDriverKey = map[int]driver.Key{ var androidKeyToUIKey = map[int]ui.Key{
7: driver.KeyDigit0, 7: ui.KeyDigit0,
8: driver.KeyDigit1, 8: ui.KeyDigit1,
9: driver.KeyDigit2, 9: ui.KeyDigit2,
10: driver.KeyDigit3, 10: ui.KeyDigit3,
11: driver.KeyDigit4, 11: ui.KeyDigit4,
12: driver.KeyDigit5, 12: ui.KeyDigit5,
13: driver.KeyDigit6, 13: ui.KeyDigit6,
14: driver.KeyDigit7, 14: ui.KeyDigit7,
15: driver.KeyDigit8, 15: ui.KeyDigit8,
16: driver.KeyDigit9, 16: ui.KeyDigit9,
19: driver.KeyArrowUp, 19: ui.KeyArrowUp,
20: driver.KeyArrowDown, 20: ui.KeyArrowDown,
21: driver.KeyArrowLeft, 21: ui.KeyArrowLeft,
22: driver.KeyArrowRight, 22: ui.KeyArrowRight,
29: driver.KeyA, 29: ui.KeyA,
30: driver.KeyB, 30: ui.KeyB,
31: driver.KeyC, 31: ui.KeyC,
32: driver.KeyD, 32: ui.KeyD,
33: driver.KeyE, 33: ui.KeyE,
34: driver.KeyF, 34: ui.KeyF,
35: driver.KeyG, 35: ui.KeyG,
36: driver.KeyH, 36: ui.KeyH,
37: driver.KeyI, 37: ui.KeyI,
38: driver.KeyJ, 38: ui.KeyJ,
39: driver.KeyK, 39: ui.KeyK,
40: driver.KeyL, 40: ui.KeyL,
41: driver.KeyM, 41: ui.KeyM,
42: driver.KeyN, 42: ui.KeyN,
43: driver.KeyO, 43: ui.KeyO,
44: driver.KeyP, 44: ui.KeyP,
45: driver.KeyQ, 45: ui.KeyQ,
46: driver.KeyR, 46: ui.KeyR,
47: driver.KeyS, 47: ui.KeyS,
48: driver.KeyT, 48: ui.KeyT,
49: driver.KeyU, 49: ui.KeyU,
50: driver.KeyV, 50: ui.KeyV,
51: driver.KeyW, 51: ui.KeyW,
52: driver.KeyX, 52: ui.KeyX,
53: driver.KeyY, 53: ui.KeyY,
54: driver.KeyZ, 54: ui.KeyZ,
55: driver.KeyComma, 55: ui.KeyComma,
56: driver.KeyPeriod, 56: ui.KeyPeriod,
57: driver.KeyAltLeft, 57: ui.KeyAltLeft,
58: driver.KeyAltRight, 58: ui.KeyAltRight,
59: driver.KeyShiftLeft, 59: ui.KeyShiftLeft,
60: driver.KeyShiftRight, 60: ui.KeyShiftRight,
61: driver.KeyTab, 61: ui.KeyTab,
62: driver.KeySpace, 62: ui.KeySpace,
66: driver.KeyEnter, 66: ui.KeyEnter,
67: driver.KeyBackspace, 67: ui.KeyBackspace,
68: driver.KeyBackquote, 68: ui.KeyBackquote,
69: driver.KeyMinus, 69: ui.KeyMinus,
70: driver.KeyEqual, 70: ui.KeyEqual,
71: driver.KeyBracketLeft, 71: ui.KeyBracketLeft,
72: driver.KeyBracketRight, 72: ui.KeyBracketRight,
73: driver.KeyBackslash, 73: ui.KeyBackslash,
74: driver.KeySemicolon, 74: ui.KeySemicolon,
75: driver.KeyQuote, 75: ui.KeyQuote,
76: driver.KeySlash, 76: ui.KeySlash,
82: driver.KeyContextMenu, 82: ui.KeyContextMenu,
92: driver.KeyPageUp, 92: ui.KeyPageUp,
93: driver.KeyPageDown, 93: ui.KeyPageDown,
111: driver.KeyEscape, 111: ui.KeyEscape,
112: driver.KeyDelete, 112: ui.KeyDelete,
113: driver.KeyControlLeft, 113: ui.KeyControlLeft,
114: driver.KeyControlRight, 114: ui.KeyControlRight,
115: driver.KeyCapsLock, 115: ui.KeyCapsLock,
116: driver.KeyScrollLock, 116: ui.KeyScrollLock,
117: driver.KeyMetaLeft, 117: ui.KeyMetaLeft,
118: driver.KeyMetaRight, 118: ui.KeyMetaRight,
120: driver.KeyPrintScreen, 120: ui.KeyPrintScreen,
121: driver.KeyPause, 121: ui.KeyPause,
122: driver.KeyHome, 122: ui.KeyHome,
123: driver.KeyEnd, 123: ui.KeyEnd,
124: driver.KeyInsert, 124: ui.KeyInsert,
131: driver.KeyF1, 131: ui.KeyF1,
132: driver.KeyF2, 132: ui.KeyF2,
133: driver.KeyF3, 133: ui.KeyF3,
134: driver.KeyF4, 134: ui.KeyF4,
135: driver.KeyF5, 135: ui.KeyF5,
136: driver.KeyF6, 136: ui.KeyF6,
137: driver.KeyF7, 137: ui.KeyF7,
138: driver.KeyF8, 138: ui.KeyF8,
139: driver.KeyF9, 139: ui.KeyF9,
140: driver.KeyF10, 140: ui.KeyF10,
141: driver.KeyF11, 141: ui.KeyF11,
142: driver.KeyF12, 142: ui.KeyF12,
143: driver.KeyNumLock, 143: ui.KeyNumLock,
144: driver.KeyNumpad0, 144: ui.KeyNumpad0,
145: driver.KeyNumpad1, 145: ui.KeyNumpad1,
146: driver.KeyNumpad2, 146: ui.KeyNumpad2,
147: driver.KeyNumpad3, 147: ui.KeyNumpad3,
148: driver.KeyNumpad4, 148: ui.KeyNumpad4,
149: driver.KeyNumpad5, 149: ui.KeyNumpad5,
150: driver.KeyNumpad6, 150: ui.KeyNumpad6,
151: driver.KeyNumpad7, 151: ui.KeyNumpad7,
152: driver.KeyNumpad8, 152: ui.KeyNumpad8,
153: driver.KeyNumpad9, 153: ui.KeyNumpad9,
154: driver.KeyNumpadDivide, 154: ui.KeyNumpadDivide,
155: driver.KeyNumpadMultiply, 155: ui.KeyNumpadMultiply,
156: driver.KeyNumpadSubtract, 156: ui.KeyNumpadSubtract,
157: driver.KeyNumpadAdd, 157: ui.KeyNumpadAdd,
158: driver.KeyNumpadDecimal, 158: ui.KeyNumpadDecimal,
160: driver.KeyNumpadEnter, 160: ui.KeyNumpadEnter,
161: driver.KeyNumpadEqual, 161: ui.KeyNumpadEqual,
} }