IanPhilips / UnityOculusAndroidVRBrowser

3D browser based on GeckoView and Oculus SDK for Unity projects built on Android (Oculus Go/Quest, maybe GearVR)
MIT License
225 stars 63 forks source link

Get the Uppercase Letter and other Umlaut Symbol #10

Closed Akravator91 closed 4 years ago

Akravator91 commented 4 years ago

Currently I am developing the VR keyboard. I am able to input Lowercase, numbers and some Symbol(e.g. !?.-+ etc.) from this keycode list here(https://android.googlesource.com/platform/frameworks/native/+/master/include/android/keycodes.h).

public void RButtonInput()
{
   int javaCode = 46; // 46 is keycode for 'r'
   CallAjc("AddKeyCode", new object[] { javaCode });
   //this is 'r' char letter.
}

However how do i implement an uppercase letter of R? And what is the keycode for other alphabet like ö ä ü ß ..?

Thank you for your help.

IanPhilips commented 4 years ago

check out the API in UnityAndroidVRARBrowser/GeckoViewPlugin/app/src/main/java/com/eyeflite/ian/geckoviewplugin/GeckoViewPLugin.java

This is an easy way to add typical characters, just pass the string version of what you want to add to the webview:

 /**
     * Converts text to keypresses and sends them to the webview.
     * @param text
     */
    public void AddKeys(String text){
        final Activity a = UnityPlayer.currentActivity;
        a.runOnUiThread(() -> {
            if (mWebView == null)
                return;
            MakeWebviewGetFocus();

            // we are just adding text
            char[] szRes = text.toCharArray(); // Convert String to Char array
            KeyEvent[] events = CharMap.getEvents(szRes);

            for (int i = 0; i < events.length; i++)
                mWebView.dispatchKeyEvent(events[i]); // MainWebView is webview

        });
    }

This will be of interest for special non-text keys that you want modified (i.e. +shift, +ctrl, etc.):

/**
     * Adds functional keycodes to the webview. Changed from dispatchKeyEvent to onKey{up,down}
     * which enables esc and enter to work perfectly in youtube.
     * @param code
     * @param metaState
     */
public void AddKeyCode(int code, int metaState){
        final Activity a = UnityPlayer.currentActivity;
        a.runOnUiThread(() -> {
            KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(),
                    KeyEvent.ACTION_DOWN,
                    code,
                    0,
                    metaState);

            mWebView.onKeyDown(code, event);
            mWebView.onKeyUp(code, event);
        });
    }
Akravator91 commented 4 years ago

I am blinded by your awesomeness!

Thankss a lottt Iann!! it workss! 👍