How to detect Context Menu
document.addEventListener('keydown', (event) => {
if (event.key === "ContextMenu") {
// Context Menu 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 Context Menu
The menu key (or Shift+F10) opens the context menu. Listen to the contextmenu event rather than this key so mouse, keyboard and long-press all work.
In React
<input onKeyDown={(e) => { if (e.key === "ContextMenu") { /* … */ } }} />