Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle keyboard navigation arrows

Tags:

On a Samsung Tablet, we have the following keyboard: enter image description here

When a clic occurred on the right bottom arrows, in the view pager, fragment is changed. I want to intercept this event or remove the arrows from the keyboard. Is it possible ?

I tried to intercept keyevent with onKeyUp and onKeyDown methods, but it's not working:

if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
  return true;
}

My problem is the same as here

like image 307
BerHug Avatar asked Sep 26 '17 13:09

BerHug


People also ask

How do you navigate with arrow keys?

Arrow keys - Using the arrow keys on the keyboard, move the cursor up, down, left, or right in the document. Ctrl and Arrow keys - Holding down Ctrl while pressing the left or right arrow keys moves the cursor one word at a time.

How do I lock the arrows on my keyboard?

On a Windows computer, to toggle scroll lock on and off, press the Scroll Lock key. On most keyboards, it's located in the control keys section of the keyboard, above the arrow keys or right of the function keys. On a Mac computer, to toggle scroll lock on and off, press F14 or Shift + F14 combination.

How do I navigate with keyboard drop down?

Use Alt + Down Arrow keys (Windows and Linux) or Option + Down Arrow keys (Mac) to open drop-down lists that do not have an Apply or Go button, and then use the Down Arrow, Up Arrow and Enter keys to select an item in the drop-down.


1 Answers

Try to use dispatchKeyEvent(KeyEvent event):

 @Override 
 public boolean dispatchKeyEvent(KeyEvent event) {

     Log.i("key pressed ", String.valueOf(event.getKeyCode()));
     if(event.getKeyCode() == KeyEvent.KEY_A /*select required keycode*/ ){
        // perform task
     }
     return super.dispatchKeyEvent(event); 
}
like image 73
Nouman Ch Avatar answered Sep 30 '22 13:09

Nouman Ch