Currently, my application have a webView that loads certain forms/websites etc.
Now I want to capture the KeyPressEvents within this webView. Below is the code I am using:
@Override
public boolean dispatchKeyEvent(KeyEvent KEvent)
{
int keyaction = KEvent.getAction();
if(keyaction == KeyEvent.ACTION_DOWN)
{
int keycode = KEvent.getKeyCode();
int keyunicode = KEvent.getUnicodeChar(KEvent.getMetaState() );
char character = (char) keyunicode;
Toast.makeText(this,"DEBUG MESSAGE KEY=" + character + " KEYCODE=" + keycode, Toast.LENGTH_SHORT).show();
}
return super.dispatchKeyEvent(KEvent);
}
Using the above code, I could only capture for backspace and numbers. Alphabets and special characters are not reflected.
Is it suppose to be like that? Or I must create my own app specific keyboard to capture the keypress events (android app specific soft keyboard)?
Just put this code in your webview and everything will work as a charm.
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return new BaseInputConnection(this, false);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With