Showing and using Android Keyboard into the game

Hi guys!

I’m building an android application with jme and it runs perfectly on computer and on my phone. The only problem is that i’d like to have a method to open the android keyboard when a button is pressed in the game (thinking of HarnessListener,to call it in the Main Activity) and possibly to consider letters typed in the android keyboard like they’re typed in a PC keyboard. I already declared setSimulateKeyboard(true) but i still can’t realize how to embed the phone keyboard into the game without hacky exploits.

I’m not using any major GUI system embedded in jme,i built it from scratch for my projects. Programming an original keyboard and running it in jme is an alternative but i think it’s pretty expensive on time and maybe it would weighs on performances.

I haven’t worked with jME on Android yet myself, but I wonder if you want to check out the InputMethodManager class:
https://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html

Specifically:
https://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#showSoftInput(android.view.View,%20int,%20android.os.ResultReceiver)

I’m not sure what you’d pass in for the View argument, I’m assuming jME is displayed in a View on Android, but not sure how you access it from within a jME application. Also the InputMethodManager is obtained through Context.getSystemService(Context.INPUT_METHOD_SERVICE);

Again, not sure if jME makes the activity’s context available or not.

1 Like

You can use JmeSystem.showSoftKeyboard()

1 Like

That’s great. A few questions though. Does JmeSystem.showSoftKeyboard() detect if a hardware keyboard is present and if so not show the keyboard, if not is there a jME specific method for detecting if a hardware keyboard is present? Also, does JmeSystem.showSoftKeyboard() also work on Windows tablets?

That’s exactly what i was looking for,thanks both!

Also,is there still a way to comunicate between my SimpleApplication and MainActivity? Informations on wiki seem outdated and are not working.

http://wiki.jmonkeyengine.org/jme3/advanced/android.html#communication-between-your-application-main-activity

This is an Android only method, so it will only work on Android. Not sure if it detects a hardware keyboard.
There’s no jME3 specific method to detect presence of a hardware keyboard but it should be possible to expose it in JmeSystem.