Skip to content

Commit 99351ba

Browse files
authored
Merge pull request hrydgard#21107 from hrydgard/android-char-event
Implement a unicode-char keyboard input event on Android.
2 parents 10d0430 + 70f1488 commit 99351ba

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

android/jni/app-android.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,18 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_keyUp(JNIEnv *, jclass, jin
12711271
return NativeKey(keyInput);
12721272
}
12731273

1274+
extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_keyChar(JNIEnv *, jclass, jint deviceId, jint unicodeChar) {
1275+
if (!renderer_inited) {
1276+
return false; // could probably return true here too..
1277+
}
1278+
1279+
KeyInput keyInput;
1280+
keyInput.deviceId = (InputDeviceID)deviceId;
1281+
keyInput.unicodeChar = unicodeChar;
1282+
keyInput.flags = KeyInputFlags::CHAR;
1283+
return NativeKey(keyInput);
1284+
}
1285+
12741286
extern "C" void Java_org_ppsspp_ppsspp_NativeApp_joystickAxis(
12751287
JNIEnv *env, jclass, jint deviceId, jintArray axisIds, jfloatArray values, jint count) {
12761288
if (!renderer_inited)

android/src/org/ppsspp/ppsspp/NativeApp.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class NativeApp {
5151

5252
public static native boolean keyDown(int deviceId, int key, boolean isRepeat);
5353
public static native boolean keyUp(int deviceId, int key);
54+
public static native boolean keyChar(int deviceId, int unicodeChar);
5455

5556
public static native void joystickAxis(int deviceId, int []axis, float []value, int count);
5657

android/src/org/ppsspp/ppsspp/PpssppActivity.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,14 +1151,25 @@ public boolean dispatchKeyEvent(KeyEvent event) {
11511151
if (!passThrough) {
11521152
switch (event.getAction()) {
11531153
case KeyEvent.ACTION_DOWN:
1154-
Log.i(TAG, "KeyEvent Down");
1154+
{
1155+
int unicode = event.getUnicodeChar();
1156+
if (unicode != 0 && !Character.isISOControl(unicode)) {
1157+
char c = (char) unicode;
1158+
Log.i(TAG, "Key char event " + unicode);
1159+
// Handle alphanumeric character
1160+
NativeApp.keyChar(NativeApp.DEVICE_ID_KEYBOARD, (int)c);
1161+
return true;
1162+
}
1163+
1164+
// Log.i(TAG, "KeyEvent Down");
11551165
if (state.onKeyDown(event)) {
11561166
return true;
11571167
}
11581168
break;
1169+
}
11591170

11601171
case KeyEvent.ACTION_UP:
1161-
Log.i(TAG, "KeyEvent Up");
1172+
// Log.i(TAG, "KeyEvent Up");
11621173
if (state.onKeyUp(event)) {
11631174
return true;
11641175
}

0 commit comments

Comments
 (0)