这是我如何在 jQuery 中捕获CTRL+C
$(window).bind('keydown', function (event) {
if (event.ctrlKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 'p':
event.preventDefault();
printFunc();
break;
}
}
});
我怎样才能对 ALT+F+P
做同样的事情
$(window).bind('keydown', function (event) {
if (event.altKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 'f':
event.preventDefault();
//************ Need help for identifying p **************
// alert('Alt-f');
printFunc();
break;
}
}
});
我也尝试过,但没有运气:
if (event.altKey && event.which == 70 && event.which == 80) {
alert('Alt-f-p');
}
最佳答案
这有效,但前提是您在“f”之前执行“p”。至少在 Chrome 中,Alt+F 可以激活浏览器功能。 <强> Live demo (click).
var pressed = {};
$(document).keydown(function(event) {
//event.altKey 70 80
var k = event.keyCode;
if (event.altKey && (k == 70 || k == 80)) {
pressed[k] = true;
console.log(k);
}
if (pressed[70] && pressed[80]) {
console.log('all pressed!');
}
});
$(document).keyup(function() {
pressed = {};
});
也许您想对其进行调整以使用不冲突的内容?
关于javascript - 捕获 Alt+F+P jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21150400/