diff --git a/internal/uidriver/mobile/ui.go b/internal/uidriver/mobile/ui.go index ed0666d8c..ebeb3a345 100644 --- a/internal/uidriver/mobile/ui.go +++ b/internal/uidriver/mobile/ui.go @@ -21,6 +21,7 @@ import ( "fmt" "runtime/debug" "sync" + "unicode" "golang.org/x/mobile/app" "golang.org/x/mobile/event/key" @@ -151,6 +152,7 @@ func (u *UserInterface) appMain(a app.App) { for e := range a.Events() { var updateInput bool + var runes []rune switch e := a.Filter(e).(type) { case lifecycle.Event: @@ -204,14 +206,20 @@ func (u *UserInterface) appMain(a app.App) { updateInput = true case key.Event: k, ok := gbuildKeyToDriverKey[e.Code] - if !ok { - continue + if ok { + switch e.Direction { + case key.DirPress, key.DirNone: + keys[k] = struct{}{} + case key.DirRelease: + delete(keys, k) + } } + switch e.Direction { case key.DirPress, key.DirNone: - keys[k] = struct{}{} - case key.DirRelease: - delete(keys, k) + if e.Rune != -1 && unicode.IsPrint(e.Rune) { + runes = []rune{e.Rune} + } } updateInput = true } @@ -221,7 +229,7 @@ func (u *UserInterface) appMain(a app.App) { for _, t := range touches { ts = append(ts, t) } - u.input.update(keys, nil, ts) + u.input.update(keys, runes, ts) } } } diff --git a/mobile/ebitenmobileview/input_android.go b/mobile/ebitenmobileview/input_android.go index 3b3d5775d..b6f781256 100644 --- a/mobile/ebitenmobileview/input_android.go +++ b/mobile/ebitenmobileview/input_android.go @@ -14,6 +14,10 @@ package ebitenmobileview +import ( + "unicode" +) + func UpdateTouchesOnAndroid(action int, id int, x, y int) { switch action { case 0x00, 0x05, 0x02: // ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_MOVE @@ -37,8 +41,8 @@ func OnKeyDownOnAndroid(keyCode int, unicodeChar int) { return } keys[key] = struct{}{} - if unicodeChar != 0 { - runes = []rune{rune(unicodeChar)} + if r := rune(unicodeChar); r != 0 && unicode.IsPrint(r) { + runes = []rune{r} } updateInput() }