如果假设按下 H 键并且鼠标在某个 div 上移动,我将 try catch 事件。
KeyPressed
和 mouseMoving
都必须为 true。
https://jsfiddle.net/bababalcksheep/1Loeh2pn/
代码:
$('#header').on("mousemove keydown", function(e) {
//only print if key 'H' is pressed and mouse is moving over $('#header')
if (e.type === 'mousemove' && e.which === 72) {
console.log('working');
}
});
最佳答案
这可能对您有帮助。
https://jsfiddle.net/1Loeh2pn/3/
$(function() {
$("#header").hover(function() {
$(document).keydown(function(e) {
if(e.which == 72){
console.log('H')
}
});
});
});
关于javascript - jQuery 捕获按下某个键时的鼠标移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35790752/