I'd like to stop webpages from binding to ⌥ (Option) only shortcuts.

E.g. these can be bound to:

  • +V
  • ++K
  • ++E
  • +++X
  • etc.

But these I want to prevent being bound to (so that their default comes into effect, I have set them up as dead keys/special character keys on my keyboard to type symbols I find important):

  • +/
  • ++E
  • etc.

I lightly edited some code from this answer on Super User to make it prevent the capture of certain shortcuts which do use the Option key and do not use the Command key. You'll want to add the keycodes for any shortcuts you want to prevent binding to the keycodes list. I started it with the codes for the two examples in your question, / and E (it doesn't care if other modifiers are pressed or not).

You can install this to your browser using an extension such as Tampermonkey.

// ==UserScript==
// @name           Disable option shortcuts
// @description    Stop websites from highjacking keyboard shortcuts
// @run-at         document-start
// @include        *
// @grant          none
// ==/UserScript==

// These are the keycodes for E and /. Find others to add by uncommenting the first alert line below and pressing that key.
keycodes = [69, 191];

(window.opera ? document.body : document).addEventListener('keydown', function(e) {
    // alert(e.keyCode ); //uncomment to find more keyCodes
    if (keycodes.indexOf(e.keyCode) != -1 && e.altKey && !(e.metaKey)) {
        e.cancelBubble = true;
    // alert("Gotcha!"); //uncomment to check if it's seeing the combo
    return false;
}, !window.opera);
| improve this answer | |
  • I would like ⌘-⌥-/ to be bindable. If another modifier is pressed, it should do what the page says. – theonlygusti Oct 3 '17 at 21:07
  • @theonlygusti It is! If the command key is pressed, this script will not do anything. It only prevents binding of combinations which (1) have Option pressed and (2) do not have Command pressed. If you also want to add Control to that list, you can add && !(e.ctrlKey) to the if statement. – Timothy Mueller-Harder Oct 3 '17 at 21:26
  • @theonlygusti Have you tried this yet? Is it lacking in any way? – Timothy Mueller-Harder Oct 5 '17 at 5:33
  • I don't really want to have to install a userscript manager if it can be avoided so I was just waiting longer. I think though if nothing happens in another week I'll make my own Safari plugin with the capability to prevent any user-specified shortcut from being bound to. – theonlygusti Oct 5 '17 at 6:21

There's no generic way to do this on macOS.

You could probably write a plugin for the specific browser(s) you want this functionality for - but no such specific plugin exists right now.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .