codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Home Page:https://www.codenameone.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

key (keyboard press/release) events never arrive

ddyer0 opened this issue · comments

This trace is from the simulator, but I see the same thing in windows-on-android where the physical
keyboard is somehow arriving in the input stream of the android app. I've also seen this with bluetooth
keyboards attached to a real android device.

Here, I typed "qwerty" with the first three keystrokes in the normal, very fast sequence.
Note that the first "up" even is 119, there's never an up event for "q" or "e"

E 22+381.657 KeyEvent 113(0x71)null true // q down
E 22+457.573 KeyEvent 119(0x77)null true // w down
E 22+546.410 KeyEvent 101(0x65)null true // e down
E 22+669.893 KeyEvent 119(0x77)null false // w up
E 23+5.395 KeyEvent 114(0x72)null true // r down
E 23+103.259 KeyEvent 114(0x72)null false // r up
E 23+300.825 KeyEvent 116(0x74)null true // t down
E 23+386.313 KeyEvent 116(0x74)null false // t up
E 23+532.205 KeyEvent 121(0x79)null true // y down
E 23+593.040 KeyEvent 121(0x79)null false // y up

Also, the non alphanumeric keys arrive strangely, or not at all.

E 5+491.973 KeyEvent -23453(0x63)null true // backspace
E 9+300.439 KeyEvent 0(0x0)null true //del
//enter doesn't arrive
// tab sometimes arrives
// control-anything doesn't arrive

I found part of an explanation and workaround, using Display.setMultiKeyMode(true).
It's not completely clear why this is off by default, and it doesn't seem right that it
bypasses the keyup function, leaving keydown/keyup unbalanced.

Ordinary typing always involves overlap between the up/down events.

Anyway, this explains/fixes some of the anomalies in the simulator, but doesn't help at all
with the class of non-printing characters being unavailable on real devices.

The latter are probably mapped to the gamekey API. These APIs were designed in an era of feature phones.

See these about the multikey mode:

// this can happen when traversing from the native form to the current form
// caused by a keypress
// We need the previous key press for Codename One issue 108 which can occur when typing into
// text field rapidly and pressing two buttons at once. Originally I had a patch
// here specifically to the native edit but that patch doesn't work properly for
// all native phone bugs (e.g. incoming phone call rejected and the key release is
// sent to the java application).

/**
* When set to true Codename One allows multiple hardware keys to be pressed at once,
* this isn't on by default since it can trigger some complexities with UI navigation to/from
* native code
* @return the multiKeyMode
*/
public boolean isMultiKeyMode() {
return multiKeyMode;
}