I'm looking for a way to listen to keydown
& keyup
events in native Android, when the user is using a soft keyboard, similar to how these events work in Javascript. I'm looking for just the event and timestamp in order to analyze keyboard dynamics.
Couldn't find documentation for this.
--EDIT--
This for an SDK that will be called from the root view. I'm trying to figure out if it's possible
If you are looking for how to detect when key is pressed, try this code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SPACE) { //I pressed space button
//some code when space is pressed
return true;
}
super.onKeyDown(keyCode, event);
}
Note that you can override this only in activity and perhaps send some event if you are in fragment
As per your requirement There is no API for this but you can create your own keyboard application, register it and then every keyboard event you can use
Refer this for details
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.