0

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

Uzair
  • 716
  • 9
  • 16

1 Answers1

1

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);
     }
 }
Sagar Zala
  • 4,854
  • 9
  • 34
  • 62
  • there is no such event as VK_UP – Uzair Sep 05 '15 at 09:17
  • this is exactly what I am doing, but it is still accepting enter and arrow keys with its default behavior – Uzair Sep 05 '15 at 09:59
  • @Uzair, return false; in if statement – Sagar Zala Sep 05 '15 at 11:09
  • but according to documentation, http://developer.android.com/reference/android/view/KeyEvent.Callback.html#onKeyDown(int, android.view.KeyEvent), we return false only when we are not handling event. – Uzair Sep 05 '15 at 12:36