How to detect Arrow Left
document.addEventListener('keydown', (event) => {
if (event.key === "ArrowLeft") {
// Arrow Left 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 Arrow Left
Arrow Left moves the caret or the previous item; in right-to-left languages, remember it moves visually left, which is the logical “next” character.
In React
<input onKeyDown={(e) => { if (e.key === "ArrowLeft") { /* … */ } }} />