How to restrict default behavior of arrow keys of remote keyboard in android

245 views Asked by At

My application works with remote Bluetooth keyboard. I have defined some predefined custom implementation on arrow keys and enter key. I want to perform only those actions whenever user press arrow key or Enter Key in my application.

But sometimes it is still showing default behavior of keys.

My Current Code is as follows

 @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
         // my custom work
         return true;
     }else{
         return super.onKeyUp(keyCode, event);
     }
 }

any idea, how I can restrict default behavior of arrow keys and enter key?

Thanks

1

There are 1 answers

4
Sagar Zala On

Use below code:

 @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KEYCODE_DPAD_RIGHT || keyCode == KEYCODE_ENTER) {
         // my custom work
         return false;
     }else{
         return super.onKeyUp(keyCode, event);
     }
 }