Reputation: 11256
I want to have a event that only triggers when you press space and move your mouse at the same time. How can you make that?
Upvotes: 1
Views: 97
Reputation: 33265
You could make one event that sets a variable to true when space is pressed down, and to false when it is released. Then you can check that variable in your mouseclick event.
Using closure, you can put this in your document ready function. This will work when clicking on the DOM with id "container"
(function () {
var space = false;
$("document").keyup(function(e) {
if (e.keyCode == 32) {
space = false;
}
}).keydown(function(e) {
if (e.keyCode == 32) {
space = true;
}
});
$("#container").click(function() {
if (space) {
// Do action
}
});
})();
Upvotes: 1
Reputation: 141879
Duplicasion
Check if the spacebar is being pressed and the mouse is moving at the same time with jQuery?
Upvotes: 0