Reputation: 169
I'm using .keydown() and .keyup() event handlers at the same time on a same object, jquery fires .keyup() whenever a key form the keyboard get released .. I want to prevent jquery from triggering .keyup() event until ALL keys get released (not only one) since I'm using multi-key-pressing functions ... any idea?
Upvotes: 1
Views: 227
Reputation: 34416
Store a count of the keydown events along with a count of the keyup events. For each iteration you will need to subtract the keyup count from the keydown count. When the count reaches 0 you will have had as many keyups as keydowns and you can then run your function.
EDIT: this is FAR from perfect, but demonstrates the concept http://jsfiddle.net/K2ny2/1/
function testKeys(u, d) {
var delta = u - d;
console.log(delta);
if(0 == delta) {
$('#result').show();
}
}
You might want to include some code to avoid the problem when someone will hold down the keys (repeats).
Upvotes: 1