How to detect Shift
document.addEventListener('keydown', (event) => {
if (event.key === 'Shift') {
// Shift was pressed
}
});
Use event.key to react to what the key means (it follows the keyboard layout) and event.code for its physical position, for example WASD in games. keyCode and which are deprecated: they still work, but their values differ between browsers and layouts.
How browsers treat Shift
Use event.shiftKey to check whether Shift is held during another key or click — don’t track Shift presses yourself. Shift changes event.key (“a” becomes “A”) but not event.code.
In React
<input onKeyDown={(e) => { if (e.key === 'Shift') { /* … */ } }} />