Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Last active March 9, 2026 15:55
Show Gist options
  • Select an option

  • Save jonathantneal/cfc2849fc85fa0ebdc9494c21b34dfba to your computer and use it in GitHub Desktop.

Select an option

Save jonathantneal/cfc2849fc85fa0ebdc9494c21b34dfba to your computer and use it in GitHub Desktop.
accelKey for KeyboardEvent — 232 bytes / 166 bytes gzipped
// Define the KeyboardEvent.accelKey getter as the platform modifier key
KeyboardEvent.prototype.__defineGetter__(
'accelKey',
KeyboardEvent.prototype.__lookupGetter__(
// The modifier key is meta for Apple devices, otherwise control
(navigator.platform ? /MacIntel|iPhone|iPad/.test(navigator.platform) : /iPad|iPhone|Mac OS X/.test(navigator.userAgent)) ? 'metaKey' : 'ctrlKey'
)
)
KeyboardEvent.prototype.__defineGetter__("accelKey",KeyboardEvent.prototype.__lookupGetter__((navigator.platform?/MacIntel|iPhone|iPad/.test(navigator.platform):/iPad|iPhone|Mac OS X/.test(navigator.userAgent))?"metaKey":"ctrlKey"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment