src/core/android/SDL_android.c
changeset 11655 ccf47d584003
parent 11653 4130b92b6be4
child 11662 a996f135cc81
     1.1 --- a/src/core/android/SDL_android.c	Wed Oct 25 18:02:11 2017 -0400
     1.2 +++ b/src/core/android/SDL_android.c	Thu Oct 26 10:41:38 2017 -0700
     1.3 @@ -31,6 +31,8 @@
     1.4  #include "SDL_android.h"
     1.5  #include <EGL/egl.h>
     1.6  
     1.7 +#include "keyinfotable.h"
     1.8 +
     1.9  #include "../../events/SDL_events_c.h"
    1.10  #include "../../video/android/SDL_androidkeyboard.h"
    1.11  #include "../../video/android/SDL_androidmouse.h"
    1.12 @@ -749,6 +751,36 @@
    1.13      (*env)->ReleaseStringUTFChars(env, text, utftext);
    1.14  }
    1.15  
    1.16 +JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeGenerateScancodeForUnichar)(
    1.17 +                                    JNIEnv* env, jclass cls,
    1.18 +                                    jchar chUnicode)
    1.19 +{
    1.20 +    SDL_Scancode code = SDL_SCANCODE_UNKNOWN;
    1.21 +    uint16_t mod = 0;
    1.22 +
    1.23 +    // We do not care about bigger than 127.
    1.24 +    if (chUnicode < 127) {
    1.25 +        AndroidKeyInfo info = unicharToAndroidKeyInfoTable[chUnicode];
    1.26 +        code = info.code;
    1.27 +        mod = info.mod;
    1.28 +    }
    1.29 +
    1.30 +    if (mod & KMOD_SHIFT) {
    1.31 +        /* If character uses shift, press shift down */
    1.32 +        SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
    1.33 +    }
    1.34 +
    1.35 +    /* send a keydown and keyup even for the character */
    1.36 +    SDL_SendKeyboardKey(SDL_PRESSED, code);
    1.37 +    SDL_SendKeyboardKey(SDL_RELEASED, code);
    1.38 +
    1.39 +    if (mod & KMOD_SHIFT) {
    1.40 +        /* If character uses shift, press shift back up */
    1.41 +        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
    1.42 +    }
    1.43 +}
    1.44 +
    1.45 +
    1.46  JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
    1.47                                      JNIEnv* env, jclass cls,
    1.48                                      jstring text, jint newCursorPosition)