dmauro / Keypress

A keyboard input capturing utility in which any key can be a modifier key.
http://dmauro.github.io/Keypress/
Apache License 2.0
3.18k stars 313 forks source link

stop_listening() doesn't seem to work as intended #69

Closed justinguk closed 9 years ago

justinguk commented 9 years ago

When binding stop_listening() to the user being focused on a text field, it should prevent prevent capture, but something doesn't prevent the listener from listening.

dmauro commented 9 years ago

So the problem you are seeing is that when a user has selected a text field, you are calling stop_listening() on your listener, but when you type into the text field, your combos are being activated? Perhaps you are also immediately calling start_listening() as well. Do you have a code sample to demonstrate this issue?

98004702 commented 9 years ago

HI David,

$(document).ready(function() {

var listener = new window.keypress.Listener();

listener.sequence_combo("shift g o", function() {
    window.location.href = "app/view-orders";
});

$('input').bind("focus", listener.stop_listening)
.bind("blur", listener.listen);

});

98004702 commented 9 years ago

Whenever I place a console.log event in the stop_listening part of the code, I can see it's being fired but the actual listener event doesn't seem to stop.

Canardlaquay commented 9 years ago

It's better to use

$('input').focus(function(){console.log("got focus")}); 

now

Replacement for .bind("blur") is just blur(func)

dmauro commented 9 years ago

The problem with your code sample is that you're calling stop_listening as if it were a function instead of a method. The value of this in that method is important. Try this: $(input).bind("blur", function() { listener.stop_listening(); }); That should do it.

dmauro commented 9 years ago

Just realized I made this mistake in my documentation :0 Sorry about that. Fixed: https://github.com/dmauro/Keypress/pull/80