Keyboard shortcuts - Android

On Android, you can use the dispatchKeyEvent and onKeyUp methods to activate shortcuts. Both methods give you a reference to a KeyEvent object. Use the isShiftPressed or isCtrlPressed method to make sure that shortcuts are not activated by accident.

override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
    return when (keyCode) {
        KeyEvent.KEYCODE_F -> {
            if (event.isCtrlPressed) {
                find()
                true
            }
        }
        else -> super.onKeyUp(keyCode, event)
    }
}

private fun find() {
    // Logic
}