How to detect Meta (Cmd / Windows key)
document.addEventListener('keydown', (event) => {
if (event.key === 'Meta') {
// Meta (Cmd / Windows key) 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 Meta (Cmd / Windows key)
Meta is Cmd on a Mac and the Windows key on PCs. Check event.metaKey. The operating system often keeps Windows-key shortcuts for itself. Firefox historically reported keyCode 224 for Cmd.
In React
<input onKeyDown={(e) => { if (e.key === 'Meta') { /* … */ } }} />