Skip to main content
Logo Appt Light

Keyboard shortcuts on Android

Most people operate their smartphones with touch, but some people use an external keyboard. Learning and using keyboard shortcuts can save you a lot of time. Shortcuts should always use a modifier key, such as CTRL or CMD to avoid clashing with system shortcuts.

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
}

Feedback?

Let us know!