Closed Akravator91 closed 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);
});
}
I am blinded by your awesomeness!
Thankss a lottt Iann!! it workss! 👍
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).
However how do i implement an uppercase letter of R? And what is the keycode for other alphabet like ö ä ü ß ..?
Thank you for your help.