Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the key code for shift+tab?

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.

like image 443
rajesh Avatar asked Jun 15 '10 09:06

rajesh


People also ask

How do you shift tab in HTML?

Your question asks for they keycode for shift+tab, but you want to detect the up key? Peter, the keyCode 16 is for the Shift key.

What is e keyCode === 13?

key 13 keycode is for ENTER key.

What is the keyCode for spacebar?

the keyCode=49 for a space.

What key number is enter?

The enter key is typically located to the right of the 3 and . keys on the lower right of the numeric keypad, while the return key is situated on the right edge of the main alphanumeric portion of the keyboard.


2 Answers

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
}
like image 132
Nick Craver Avatar answered Oct 18 '22 21:10

Nick Craver


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();
    }
}
like image 24
Modular Avatar answered Oct 18 '22 22:10

Modular