Search code examples
androidkeycode

How is the Keyboard KeyCode named in Android?


Does anyone know what is the name of the checkmark blue key code?

enter image description here


Solution

  • It's either KeyEvent.KEYCODE_ENTER or EditorInfo.IME_ACTION_DONE depending on what listener you use. You need a OnEditorActionListener for software keyboards and a OnKeyListener for hardware keyboards:

    val editText = EditText()
    editText.setOnKeyListener { _, keyCode, event ->
        if (keyCode == KeyEvent.KEYCODE_ENTER) {
            // do something
            true
        } else {
            false
        }
    }
    editText.setOnEditorActionListener { _, actionId, _ ->
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            // do something
            true
        } else {
            false
        }
    }