Add support for enabling/disabling KeyEvent simulation for soft keyboards on Android similar to MouseEvents.

experimental
iwgeric 10 years ago
parent 249f62fe95
commit 1ed1463476
  1. 5
      jme3-android/src/main/java/com/jme3/app/AndroidHarness.java
  2. 7
      jme3-android/src/main/java/com/jme3/input/android/AndroidInputHandler.java
  3. 30
      jme3-android/src/main/java/com/jme3/input/android/AndroidKeyHandler.java
  4. 20
      jme3-core/src/main/java/com/jme3/system/AppSettings.java

@ -107,6 +107,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
* JoyAxisTriggers. * JoyAxisTriggers.
*/ */
protected boolean joystickEventsEnabled = false; protected boolean joystickEventsEnabled = false;
/**
* If true KeyEvents are generated from TouchEvents
*/
protected boolean keyEventsEnabled = true;
/** /**
* If true MouseEvents are generated from TouchEvents * If true MouseEvents are generated from TouchEvents
*/ */
@ -224,6 +228,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
settings.setEmulateMouse(mouseEventsEnabled); settings.setEmulateMouse(mouseEventsEnabled);
settings.setEmulateMouseFlipAxis(mouseEventsInvertX, mouseEventsInvertY); settings.setEmulateMouseFlipAxis(mouseEventsInvertX, mouseEventsInvertY);
settings.setUseJoysticks(joystickEventsEnabled); settings.setUseJoysticks(joystickEventsEnabled);
settings.setEmulateKeyboard(keyEventsEnabled);
settings.setBitsPerPixel(eglBitsPerPixel); settings.setBitsPerPixel(eglBitsPerPixel);
settings.setAlphaBits(eglAlphaBits); settings.setAlphaBits(eglAlphaBits);

@ -136,8 +136,7 @@ public class AndroidInputHandler implements TouchInput {
} }
public void loadSettings(AppSettings settings) { public void loadSettings(AppSettings settings) {
// TODO: add simulate keyboard to settings keyboardEventsEnabled = settings.isEmulateKeyboard();
// keyboardEventsEnabled = true;
mouseEventsEnabled = settings.isEmulateMouse(); mouseEventsEnabled = settings.isEmulateMouse();
mouseEventsInvertX = settings.isEmulateMouseFlipX(); mouseEventsInvertX = settings.isEmulateMouseFlipX();
mouseEventsInvertY = settings.isEmulateMouseFlipY(); mouseEventsInvertY = settings.isEmulateMouseFlipY();
@ -259,6 +258,10 @@ public class AndroidInputHandler implements TouchInput {
this.keyboardEventsEnabled = simulate; this.keyboardEventsEnabled = simulate;
} }
public boolean isSimulateKeyboard() {
return keyboardEventsEnabled;
}
public void setOmitHistoricEvents(boolean dontSendHistory) { public void setOmitHistoricEvents(boolean dontSendHistory) {
this.dontSendHistory = dontSendHistory; this.dontSendHistory = dontSendHistory;
} }

@ -108,20 +108,21 @@ public class AndroidKeyHandler implements View.OnKeyListener {
} }
if (androidInput.isSimulateKeyboard()) {
KeyInputEvent kie; KeyInputEvent kie;
char unicodeChar = (char)event.getUnicodeChar(); char unicodeChar = (char)event.getUnicodeChar();
int jmeKeyCode = AndroidKeyMapping.getJmeKey(keyCode); int jmeKeyCode = AndroidKeyMapping.getJmeKey(keyCode);
boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN; boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
boolean repeating = pressed && event.getRepeatCount() > 0; boolean repeating = pressed && event.getRepeatCount() > 0;
kie = new KeyInputEvent(jmeKeyCode, unicodeChar, pressed, repeating); kie = new KeyInputEvent(jmeKeyCode, unicodeChar, pressed, repeating);
kie.setTime(event.getEventTime()); kie.setTime(event.getEventTime());
androidInput.addEvent(kie); androidInput.addEvent(kie);
// logger.log(Level.FINE, "onKey keyCode: {0}, jmeKeyCode: {1}, pressed: {2}, repeating: {3}", // logger.log(Level.FINE, "onKey keyCode: {0}, jmeKeyCode: {1}, pressed: {2}, repeating: {3}",
// new Object[]{keyCode, jmeKeyCode, pressed, repeating}); // new Object[]{keyCode, jmeKeyCode, pressed, repeating});
// logger.log(Level.FINE, "creating KeyInputEvent: {0}", kie); // logger.log(Level.FINE, "creating KeyInputEvent: {0}", kie);
}
// consume all keys ourself except Volume Up/Down and Menu // consume all keys ourself except Volume Up/Down and Menu
// Don't do Menu so that typical Android Menus can be created and used // Don't do Menu so that typical Android Menus can be created and used
@ -133,6 +134,7 @@ public class AndroidKeyHandler implements View.OnKeyListener {
} else { } else {
return true; return true;
} }
} }
} }

@ -455,6 +455,26 @@ public final class AppSettings extends HashMap<String, Object> {
return getBoolean("TouchEmulateMouseFlipY"); return getBoolean("TouchEmulateMouseFlipY");
} }
/**
* Enable or disable keyboard emulation on touchscreen based devices.
* This will convert soft keyboard key presses on the touchscreen
* into the appropriate key events.
*
* @param emulateKeyboard If soft keyboard emulation should be enabled.
*/
public void setEmulateKeyboard(boolean emulateKeyboard) {
putBoolean("TouchEmulateKeyboard", emulateKeyboard);
}
/**
* Returns true if keyboard emulation is enabled, false otherwise.
*
* @return Soft keyboard emulation mode.
*/
public boolean isEmulateKeyboard() {
return getBoolean("TouchEmulateKeyboard");
}
/** /**
* @param frameRate The frame-rate is the upper limit on how high * @param frameRate The frame-rate is the upper limit on how high
* the application's frames-per-second can go. * the application's frames-per-second can go.

Loading…
Cancel
Save