How to activate an action when a keyboard key is pressed.

How to activate an action when a keyboard key is pressed.

  

Hello

I have an action on a mobile app screen that I want to run every time a user press the arrow key on a keyboard.  The action is currently being activated by clicking a button but I need the action to be listening for the arrow key and to run as soon as the arrow is being typed on the keyboard. 


Does anyone have any ideas on how this can be done?


Thanks!


You can call that action on whenever someone types in the textbox but inside action you will need javascript function to check which key is pressed. If it is arrow key, execute the logic which you want to run else end the action there only.

I just googled and this javascript code you can use.

https://stackoverflow.com/questions/5597060/detecting-arrow-key-presses-in-javascript