I am trying to capture event if suppose key H is pressed and mouse is moving over some div.
KeyPressed
and mouseMoving
both have to be true.
https://jsfiddle.net/bababalcksheep/1Loeh2pn/
Code:
JavaScript
x
7
1
$('#header').on("mousemove keydown", function(e) {
2
//only print if key 'H' is pressed and mouse is moving over $('#header')
3
if (e.type === 'mousemove' && e.which === 72) {
4
console.log('working');
5
}
6
});
7
Advertisement
Answer
This may helpful for you.
https://jsfiddle.net/1Loeh2pn/3/
JavaScript
1
10
10
1
$(function() {
2
$("#header").hover(function() {
3
$(document).keydown(function(e) {
4
if(e.which == 72){
5
console.log('H')
6
}
7
});
8
});
9
});
10