0

I use a Wacom tablet that has touch gestures enabled. For some reason, when using Firefox, left and right scrolling is interpreted as left and right arrow keypresses.

This wreaks havoc with some websites, like DuckDuckGo and Google images, because if you're trying to scroll through the page any not perfectly vertical scroll movement suddenly starts changing tabs or selecting things (DuckDuckGo has keyboard navigation, so that if you hit left or right arrows it tabs you between web search, image search, shopping and maps).

I realise I could use a different browser (no, never, cold, dead hands, etc.), or turn off touch gestures, but for most websites it's fine, and having touch scrolling is great.

So I'm trying to turn it off with Tampermonkey, but my knowledge of JavaScript / the DOM is too limited. I've found if I edit the source of one of the pages in the Developer tools and add this script it succesfully captures the keystroke events and stops the bad behaviour:

window.addEventListener('keydown', (event) => {
      if (event.code === 'ArrowRight' || event.code === 'ArrowLeft') {}
});

I tried to add this to a userscript, but it didn't work, I also tried using this in a userscript

window.onkeydown = function(event) {
    if (event.code === 'ArrowRight'||event.code === 'ArrowLeft'){
      console.log('ohai');
      event.preventDefault();
      event.stopPropagation();
      return false;
    }
};

The console.log() happens, but the keydown event still goes to whatever script is doing the tabbing in DuckDuckGo.

How do I block left and right arrow keystrokes in a userscript?

2
  • 1
    Keystrokes can be blocked with Autohotkey filtered by the window title. Also I'd give a try alternative ways for scrolling. E.g. drag scroll is very good for use with pen tablet.
    – Mikhail V
    Commented Jan 12, 2021 at 10:08
  • I didn't think of AHK, great idea.
    – stib
    Commented Jan 13, 2021 at 5:36

1 Answer 1

0

I haven't been able to find a built-in method for this from Mozilla, so using Autohotkey, as suggested by @Mikhail-V seems to be the workaround.

I wrote an AHK script that turns left and right arrow presses into left and right wheel events. Now the problem is that this disables the left and right arrow keys, so I added a check to see if scrollLock was on. If it is then left and right go to mouseLeft and mouseRight, otherwise they go to left and right keypresses.

#if winActive("ahk_class MozillaWindowClass") and GetKeyState("ScrollLock", "T")
#MaxHotkeysPerInterval, 200 ;the tablet sends a LOT of keypresses
Left::WheelLeft
Right::WheelRight

You must log in to answer this question.

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