Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created January 26, 2023 14:37
Show Gist options
  • Save jonathantneal/cfc2849fc85fa0ebdc9494c21b34dfba to your computer and use it in GitHub Desktop.
Save jonathantneal/cfc2849fc85fa0ebdc9494c21b34dfba to your computer and use it in GitHub Desktop.
modifierKey for KeyboardEvent — 164 bytes / 140 bytes gzipped
// Define the KeyboardEvent.modifierKey getter as the platform modifier key
KeyboardEvent.prototype.__defineGetter__(
'modifierKey',
KeyboardEvent.prototype.__lookupGetter__(
// The modifier key is meta for Apple devices, otherwise control
/^(MacIntel|iPhone)$/.test(navigator.platform) ? 'metaKey' : 'ctrlKey'
)
)
KeyboardEvent.prototype.__defineGetter__("modifierKey",KeyboardEvent.prototype.__lookupGetter__(/^(MacIntel|iPhone)$/.test(navigator.platform)?"metaKey":"ctrlKey"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment