How to detect Semicolon (;)
document.addEventListener('keydown', (event) => {
if (event.key === ";") {
// Semicolon (;) 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 Semicolon (;)
Punctuation keys move around on international keyboards: on German keyboards this key types Ö. Use event.key for the character typed, and event.code only for physical positions such as game controls.
In React
<input onKeyDown={(e) => { if (e.key === ";") { /* … */ } }} />