what is the key code for shift+tab?

JavascriptHtml

Javascript Problem Overview


I am working on key mapping. The problem is that when I press the TAB button down it navigates to the next input field.

>TAB has key of 9 and
>DOWN has key of 40

But, what is the JavaScript key code to go to the previous input field (SHIFT + TAB)?

What I want is to go to next link; what is keycode or code for the previous link?

Please help. Thanks.

Javascript Solutions


Solution 1 - Javascript

There's no "keycode", it's a separate property on the event object, like this:

if(event.shiftKey && event.keyCode == 9) { 
  //shift was down when tab was pressed
}

Solution 2 - Javascript

e.keyCode has been deprecated for sometime. Use "e.key" KeyboardEvent.key instead.

Usage:

e.shiftKey && e.key === 'Tab'

Example:

function clicked(e) {
    if (e.shiftKey && e.key === 'Tab') {
        // Do whatever, like e.target.previousElementSibling.focus();
    }
}

Solution 3 - Javascript

you can use the event.shiftKey property for that: <http://www.java2s.com/Code/JavaScript/Event/Shiftkeypressed.htm>

Solution 4 - Javascript

This way it worked for me
By checking first if one of key is pressed(tab/shift ) and then check other inside it:

if (e.code === "Tab") {
  if (e.shiftKey) {//shift+tab pressed
      //Code
  } else {//only tab pressed
      //Code
  }
}

Solution 5 - Javascript

in my GWT case

if(event.isShiftKeyDown() && event.getNativeKeyCode() == KeyCodes.KEY_TAB){
    //Do Something
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrajeshView Question on Stackoverflow
Solution 1 - JavascriptNick CraverView Answer on Stackoverflow
Solution 2 - JavascriptModularView Answer on Stackoverflow
Solution 3 - JavascriptknittlView Answer on Stackoverflow
Solution 4 - JavascriptRanaView Answer on Stackoverflow
Solution 5 - JavascripttouchchandraView Answer on Stackoverflow