Detecting a digit from either row
document.addEventListener('keydown', (e) => {
if (/^[0-9]$/.test(e.key)) {
console.log('digit', Number(e.key)); // top row or numpad
}
});On French AZERTY keyboards the top row types symbols (&, é, " …) without Shift, so e.key is not a digit there — another reason to test e.key rather than assume positions.
JavaScript Keycode FinderPress any key and instantly see every property of the keyboard event, with a copy-ready keydown snippet for shortcuts.
Open the tool Frequently asked questions
Is event.key upper or lower case for number?
Letters follow Shift and Caps Lock: event.key is “a” normally and “A” with Shift. event.code stays KeyA either way.
Do key codes change with the keyboard layout?
event.key changes with the layout (on a French AZERTY keyboard the A position types Q); event.code always names the physical key.
Should I still use keyCode?
No — it’s deprecated. Use event.key for characters and event.code for positions.