Is there any chance to support opening/closing on-screen keyboard on Android and to process KeyPress events from it? I would like to use it as possible and usual input method for typing player names, etc.
I could open/close the keyboard from external library (by use of JNI), but not sure whether KeyPress can read the input from it. Providing some support to this functionality in ZGE, e.g., some function(s), would be quite helpful.
BTW I tested also to HW keyboard and mouse connected via USB OTG and KeyPress did not give any inputs; except of releasing mouse which produced { (LMB press) event.
Opening/closing on-screen keyboard on Android
Moderator: Moderators
I would expect an external keyboard to send KeyDown messages. Try adding a log message in onKeyDown method in Zge.java just to see if it is called at all. Maybe it is just the individual keycodes that is sent to ZGE incorrectly, then it should be easy to fix.
About open/close keyboard I'm not sure how it is done. I found this thread but it does not mention JNI: http://stackoverflow.com/questions/5593 ... mmatically
About open/close keyboard I'm not sure how it is done. I found this thread but it does not mention JNI: http://stackoverflow.com/questions/5593 ... mmatically
Ok, I'll test it this evening again. In my previous test I just used arrow keys (<>^_).VilleK wrote:Try adding a log message in onKeyDown method in Zge.java just to see if it is called at all. Maybe it is just the individual keycodes that is sent to ZGE incorrectly, then it should be easy to fix.
This thread is about creating applications in Java. To switch soft keyboard on/off during runtime from NDK, one way is to use JNI; as discussed in https://groups.google.com/forum/#!topic ... mpwzH_PItc. Maybe, there is also another way using NDK native activity...VilleK wrote:About open/close keyboard I'm not sure how it is done. I found this thread but it does not mention JNI: http://stackoverflow.com/questions/5593 ... mmatically
Anyway, I tried to set android:windowSoftInputMode="stateVisible" in AndroidManifest.xml and did not work for ZGE on Android 4.0. That's maybe it was added only to API level 14. But this is just the means for testing; in the final solution I would like to control showing/hiding soft keyboard by application.
Interesting observations:
1. If physical keyboard is not connected by OTG cable, android:windowSoftInputMode="stateVisible" works and opens a soft keyboard on Android 4.4.2 (API 19).
2. ZGE is not able to take events from soft keyboard anyway. I tested several letter keys.
3. If physical keyboard is available, ZGE on Android can react on events, but in different way than on Windows: it takes upper-case / lower-case of KeyPress.Keys into account, so key A means you must press Shift+A, a reacts to key A, key < requires pressing Shift+, (which is < symbol on my keyboard) and not left arrow, etc.
4. If physical keyboard is connected, the android:windowSoftInputMode="stateVisible" does not cause opening the soft keyboard.
5. Mouse connected by OTG cable produces clicks/touches in a normal way, so ZGE can process them without problems.
Usage of physical keyboard on Android devices is quite rare, so developers of ZGE applications should not rely on this feature too much. It's more-or-less a curiosity.
What can be improved in ZGE is the point 2. I can prepare an external library for opening/closing soft keyboard, but if ZGE is not able to react to it, the effort is useless.
BTW for my current project, I'm tempted to implement my own "virtual keyboard" within ZGE application. This would give me full control ... but also would require some more effort. Maybe soft keyboard would be more standard solution...(?) What do you think?
1. If physical keyboard is not connected by OTG cable, android:windowSoftInputMode="stateVisible" works and opens a soft keyboard on Android 4.4.2 (API 19).
2. ZGE is not able to take events from soft keyboard anyway. I tested several letter keys.
3. If physical keyboard is available, ZGE on Android can react on events, but in different way than on Windows: it takes upper-case / lower-case of KeyPress.Keys into account, so key A means you must press Shift+A, a reacts to key A, key < requires pressing Shift+, (which is < symbol on my keyboard) and not left arrow, etc.
4. If physical keyboard is connected, the android:windowSoftInputMode="stateVisible" does not cause opening the soft keyboard.
5. Mouse connected by OTG cable produces clicks/touches in a normal way, so ZGE can process them without problems.
Usage of physical keyboard on Android devices is quite rare, so developers of ZGE applications should not rely on this feature too much. It's more-or-less a curiosity.
What can be improved in ZGE is the point 2. I can prepare an external library for opening/closing soft keyboard, but if ZGE is not able to react to it, the effort is useless.
BTW for my current project, I'm tempted to implement my own "virtual keyboard" within ZGE application. This would give me full control ... but also would require some more effort. Maybe soft keyboard would be more standard solution...(?) What do you think?
It is strange if the soft keyboard does not send key events to the active application.
I found this: http://stackoverflow.com/questions/1127 ... -key-press
Maybe you can try the solution suggested there and tell me if it works?
I found this: http://stackoverflow.com/questions/1127 ... -key-press
Maybe you can try the solution suggested there and tell me if it works?
Inspired by the previous code example, I extended Zge.java by:
The log shows correct Unicode codes of pressed and released keys, but ZGE application does not react to them. Is calling of native methods correct? I Attach the example project with modified sources and AndroidManifest.xml.
Tested on Google Keyboard and Hacker's Keyboard. Both gave the same results.
Code: Select all
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyaction = event.getAction();
if(keyaction == KeyEvent.ACTION_DOWN) {
NativeKeydown(event.getUnicodeChar());
Log.i("key down", String.valueOf(event.getUnicodeChar()));
} else if(keyaction == KeyEvent.ACTION_UP) {
NativeKeyup(event.getUnicodeChar());
Log.i("key up", String.valueOf(event.getUnicodeChar()));
}
return super.dispatchKeyEvent(event);
}
Tested on Google Keyboard and Hacker's Keyboard. Both gave the same results.
- Attachments
-
- com.rado1.test.zip
- testing ZGE project + Android sources
- (5.9 KiB) Downloaded 788 times
Just for curiosity, I created a small external library which is able to toggle soft keyboard from ZGE. It works also on old Android versions; it is compiled for android-8. Currently, in order to achieve better flexibility in testing, it is implemented in the way that calls static Java method from ZgeActivity.java by JNI. So in order to run ZGE application properly, you need to replace ZgeActivity.java. Original AndroidManifest.xml file (as generated by ZGE) should be used for compilation; not the modified one as mentioned in my previous post.
The attachment contains all necessary files, including a testing project - toggles the soft keyboard by tapping anywhere.
The attachment contains all necessary files, including a testing project - toggles the soft keyboard by tapping anywhere.
- Attachments
-
- test.zip
- library for switching soft keyboard + testing project + modified ZgeActivity.java
- (7.78 KiB) Downloaded 774 times