1

I often hit the right click on my trackpad on accident. With Firefox open it opens the context menu.

Can I add a key, Shift, Ctrl, alt, etc., to combine with the right click to prevent this accident happening in Firefox so often? I use Firefox with Pentadactyl if that helps.

I see that there are many similar questions, but I don't see any that fit my solution or are up to date.

1
  • if you can edit the title, it might be better to change it to "Can I require a key with right click...". The current title makes it sound like you're trying to add a binding rather than restrict one.
    – pyrocrasty
    Commented Jun 16, 2015 at 5:23

1 Answer 1

1

You can use the following Javascript to disable the context menu except when activated with Alt+RightClick.

function f(ev) { if (!ev.altKey) { ev.preventDefault(); return false; } }
document.addEventListener('contextmenu',f, false)

With Pentadactyl

Since you're running pentadactyl, you can simply add the following lines to your .pentadactylrc:

:js function f(ev) { if (!ev.altKey) { ev.preventDefault(); return false; } }
:js document.addEventListener('contextmenu',f, false)

Notes

  • This will only work if the Firefox setting dom.event.contextmenu.enabled is set to true. This is the default value, so it should be fine unless you (or an extension) have changed it.

    If it's been set to false, you need to change it. You can do this by opening the page about:config in Firefox, searching for the entry and double-clicking to toggle it. Alternatively, in Pentadactyl, execute the command

    set! dom.event.contextmenu.enabled=true
    
  • If you want to remove the block, the can use the Javascript function

    document.removeEventListener('contextmenu',f) 
    

    So in Pentadactyl, :js document.removeEventListener('contextmenu',f)

3
  • I've added the code you provided to my .pentadactylrc and confirmed that my about:config setting you mentioned was set. I still get the context menu without Alt. Is it a conflict with another add on? Commented Jun 17, 2015 at 7:21
  • No, it's my fault. I stupidly copied the wrong line. The second line is actually the one I was using to remove the handler, rather than the one to add it. I've edited my answer, so it should work now. Sorry about that.
    – pyrocrasty
    Commented Jun 17, 2015 at 8:03
  • Awesome! Bonus points for the Pentadactyl explanations! Commented Jun 18, 2015 at 19:32

You must log in to answer this question.

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