Sometimes, we want to detect shift+tab press with JavaScript.
In this article, we’ll look at how to detect shift+tab press with JavaScript.
How to detect shift+tab press with JavaScript?
To detect shift+tab press with JavaScript, we can check if the shiftKey is true and the keyCode is 9.
For instance, we write
if (event.shiftKey && event.keyCode === 9) {
// ...
}
to check if the shiftKey is pressed and while tab is pressed.
The keyCode for the tab key is 9.
event is the keyboard event object we get from the keyboard event handler callback’s parameter.
Conclusion
To detect shift+tab press with JavaScript, we can check if the shiftKey is true and the keyCode is 9.