2

Steps to reproduce:

  1. Visit this page. It is a JSFiddle consisting entirely of

    window.onkeydown = function(e) { e.preventDefault(); };
    
  2. Click inside the gray area, under the white top bar, to give focus to the main area.

  3. Press Ctrl+Z to enter Pass Through mode.

  4. Press Esc. This will fail, because the key is intercepted by the JavaScript and never sent to Pentadactyl.

This is easy to mitigate in the example by clicking on the top bar to transfer focus away from the area containing the onkeydown, allowing Escape to get through and exit Pass Through mode. However, I'm working with a site that intercepts all key presses (with preventDefault) via window.onkeydown, so there's nowhere to transfer the focus away to.

The only solution I've been able to find is to create a new tab and then close it (d). However, this requires use of the mouse (as the t shortcut no longer works because we're in Pass Through mode), and it's a hacky workaround.

Is there any way to exit Pass Through mode with only the keyboard, on a site that intercepts all key presses?

1 Answer 1

2
  • On the JSFiddle you linked to, at least, Ctrl-TAB and Ctrl-Shift-TAB still function, so you can switch to the next tab and back to cancel passthrough mode. For some reason, you still can't access the command line, but other keys work, so you can always refresh the page with r to fix that.

  • As a less hackish solution, you could define a command in your .pentadactylrc file to stop the page stealing key events:

    command! nointercept -js document.addEventListener('keydown', function(e) { e.stopImmediatePropagation(); return false;}, true);
    

    Then if you execute :nointercept on the page before clicking on the main area, you'll be able to escape passthrough mode. With this method, the command line works normally after leaving passthrough mode.

    If you only want to stop the page intercepting the Esc key, you can modify the command to test for e.keyCode===27.

  • If you want to apply the above code automatically, you could turn it into a userscript (requires Greasemonkey as you probably know). The following should work if you fill in the correct URLs or URL patterns after @include

    // ==UserScript==
    
    // @name           nointercept
    // @description    Prevent site from stealing key presses
    
    // @run-at         document-start
    // @include        http://site.url        
    
    // ==/UserScript==        
    
    document.addEventListener(
        'keydown',
        function(e) { e.stopImmediatePropagation(); return false; },
        true
    );
    

You must log in to answer this question.

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