diff --git a/android/app/src/main/cpp/main.c b/android/app/src/main/cpp/main.c index e733f357..341cda96 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) + { + Com_QueueEvent( 0, SE_CHAR, keycode, qtrue, 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..893bd5a9 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; @@ -35,6 +36,7 @@ import static android.system.Os.setenv; public class MainActivity extends SDLActivity // implements KeyEvent.Callback { + private static final String SUPPORTED_ASCII = "qwertyuiop[]asdfghjkl;'\\ZXCVBNM<>?`1234567890-=~!@#$%^&*()_+"; private int permissionCount = 0; private static final int READ_EXTERNAL_STORAGE_PERMISSION_ID = 1; private static final int WRITE_EXTERNAL_STORAGE_PERMISSION_ID = 2; @@ -72,6 +74,17 @@ public class MainActivity extends SDLActivity // implements KeyEvent.Callback super.onDestroy(); } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + //ASCII characters directly passed into the engine + if (SUPPORTED_ASCII.indexOf(event.getUnicodeChar()) >= 0) { + nativeKey(event.getUnicodeChar(), event.getAction()); + return true; + } + //special keys using SDL + return super.dispatchKeyEvent(event); + } + /** * Initializes the Activity only if the permission has been granted. */ @@ -246,6 +259,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");