javascriptkrl

remove J and K key events on twitter.com


I built a browser extension that extends twitter.com. It opens a jQuery UI modal window, and has some text inputs. When I type in those inputs, it works, except for the J and K keys. Those keys are part of some custom Twitter event (scrolling between tweets). I can get all the keys to actually type the letter into the box except for those two.

I want to know how to unbind the keypress stuff for those two keys so that I can get those two letters to type. Any ideas on how to unbind them? I have tried catching the event and preventing the default on it...didn't help. I have caught it and returned true/false, also no help. Please let me know.


Solution

  • I ran into the same issue with textareas and input fields on Twitter.com when I built a browser extension to enhance the page. I was able to get everything to work as expected by targeting the specific input and textareas that my extension created and then stoping the propagation of the keypress event.

    $("selector-for-inputs-created-by-extension")
        .bind("keypress", function(e) {
            e.stopPropagation();
        });
    

    Hope that helps clarify things.