c# – Capture keystroke Android


I am making an Android application and I need to capture the keys that are pressed on the keyboard. I am new to programming in Xamarin and it would help me a lot if someone could guide me.


The common thing is to do it with the onKeyDown() method,

for example if we want to detect when the "Back" key is clicked:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        //Implemenetar accción,Se pulso la tecla back!
    return super.onKeyDown(keyCode, event);


  • Here you can find a list of all the constants, to detect any key:


  • You can also use the onKeyUp() method , but the difference is that it is executed when the key is released.
Scroll to Top