From 8bb0124fe64d56d70c55d20e04001ca5f691b6fe Mon Sep 17 00:00:00 2001 From: Lubos Date: Fri, 2 Dec 2022 09:58:21 +0100 Subject: [PATCH] Support external keyboards --- android/app/src/main/cpp/main.c | 10 +++++++++- .../main/java/com/drbeef/ioq3quest/MainActivity.java | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/cpp/main.c b/android/app/src/main/cpp/main.c index e733f357..6e6ebd0b 100644 --- a/android/app/src/main/cpp/main.c +++ b/android/app/src/main/cpp/main.c @@ -36,6 +36,14 @@ JNIEXPORT void JNICALL Java_com_drbeef_ioq3quest_MainActivity_nativeFocusChanged g_HasFocus = focus; } +JNIEXPORT void JNICALL Java_com_drbeef_ioq3quest_MainActivity_nativeKey(JNIEnv *env, jclass clazz, jint keycode, jint action) +{ + if ((action == 0) || (action == 1)) + { + Com_QueueEvent( 0, SE_CHAR, keycode, action == 0, 0, NULL ); + } +} + JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { g_JavaVM = vm; @@ -121,4 +129,4 @@ int main(int argc, char* argv[]) { VR_Destroy(engine); return 0; -} +} \ No newline at end of file diff --git a/android/app/src/main/java/com/drbeef/ioq3quest/MainActivity.java b/android/app/src/main/java/com/drbeef/ioq3quest/MainActivity.java index c11cd6da..ea06321c 100644 --- a/android/app/src/main/java/com/drbeef/ioq3quest/MainActivity.java +++ b/android/app/src/main/java/com/drbeef/ioq3quest/MainActivity.java @@ -8,6 +8,7 @@ import android.os.Bundle; import android.os.RemoteException; import android.util.Log; import android.util.Pair; +import android.view.KeyEvent; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; @@ -72,6 +73,14 @@ public class MainActivity extends SDLActivity // implements KeyEvent.Callback super.onDestroy(); } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + //ASCII characters directly passed into the engine + nativeKey(event.getKeyCode(), event.getAction()); + //special keys using SDL + return super.dispatchKeyEvent(event); + } + /** * Initializes the Activity only if the permission has been granted. */ @@ -246,6 +255,7 @@ public class MainActivity extends SDLActivity // implements KeyEvent.Callback public static native void nativeCreate(MainActivity thisObject); public static native void nativeFocusChanged(boolean focus); + public static native void nativeKey(int keycode, int action); static { System.loadLibrary("main");