The incoming keyboard event.
Parsed binding returned from parseBinding.
true if the event matches the binding.
const b = parseBinding("mod+shift+r");
matches(event, b); // true when ⌘⇧R (mac) or Ctrl+Shift+R (other)
export function matches(event: KeyboardEvent, binding: ParsedBinding): boolean {
if (event.metaKey !== binding.meta) return false;
if (event.ctrlKey !== binding.ctrl) return false;
if (event.altKey !== binding.alt) return false;
// `?` is produced by Shift+/ — event.key is already "?", so don't require shift
// separately. For other keys, enforce the shift flag strictly.
if (binding.key !== "?" && event.shiftKey !== binding.shift) return false;
return event.key.toLowerCase() === binding.key.toLowerCase();
}
Checks whether a
KeyboardEventmatches aParsedBinding. Matching is strict on modifiers — any modifier that is not required in the binding must not be held down, soctrl+swill not also fire forctrl+shift+s. Key comparison is case-insensitive viaevent.key.