I'm making an Android application and I need to capture the keys that are pressed on the keyboard. I am new programming in Xamarin and it would help me a lot if someone could guide me.
I'm making an Android application and I need to capture the keys that are pressed on the keyboard. I am new programming in Xamarin and it would help me a lot if someone could guide me.
The common thing is to do it with the method onKeyDown () ,
for example if we want to detect when the "Back" key is clicked:
@Override
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);
}
For keyboard events on Xamarin Android you must implement the interface KeyEvent.ICallback .
The interface has these methods:
Xamarin's KeyEvent Android documentation: Link
If you are in an Activity, you would have to do it in the following way:
public class MiActivity : Activity , KeyEvent.ICallback
{
public override bool OnKeyUp(Keycode keyCode, KeyEvent e)
{
//codigo asociado a la key presionada
return base.OnKeyUp(keyCode, e);
}
}