How to detect Arrow Down
document.addEventListener('keydown', (event) => {
if (event.key === "ArrowDown") {
// Arrow Down 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 Down
Arrow Down opens native <select> lists (with Alt on Windows) and moves to the next item in menus and listboxes. Call preventDefault() in custom widgets so the page doesn’t scroll.
In React
<input onKeyDown={(e) => { if (e.key === "ArrowDown") { /* … */ } }} />