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?