Delete key events J and K 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 these inputs, it works, with the exception of the J and K. keys. These keys are part of some Twitter custom event (scroll between tweets). I can get all the keys to actually enter a letter in the field, except for those two.

I want to know how to untie the material keypressfor these two keys so that I can type these two letters. Any ideas on how to untie them? I tried to catch the event and prevent it by default ... didn't help. I caught it and returned true / false, as well as no help. Please let me know.

+5
source share
3 answers

I came across the same issue with text fields and input fields on Twitter.com when I built a browser extension to improve the page. I was able to get everything to work as expected by targeting the specific input and text fields that my extension created and then stopping the distribution of the keypress event.

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

Hope this helps clarify the situation.

+1
source

It sounds very similar to the problem I encountered when Google changes the up and down arrow keys. This is where I solved this on SO after some help. Basically I stopped the event like this (for me it is up and down, find the key codes for your j and k):

if (event.keyCode == 40 || event.keyCode == 38)  {
    event.cancelBubble = true;
    event.stopPropagation();            
    return false;
}
+4
source

Twitter, , jQuery . JavaScript :

$(document).data('events').keydown;
$(document).data('events').keypress;
$(document).data('events').keyup;

With the help of basic trial and error, we can narrow the scope of the keystroke event by deleting these events and testing the missing functionality.

// Results in j/k keys no longer moving up/down
$(document).data('events').keypress = [];

This, of course, is a kind of approach based on hacking and cutting, but useful for narrowing things down.

+3
source

All Articles