以下是我如何在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');
}
答案 0 :(得分:1)
这有效,但只有在“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 = {};
});
也许你会想让它适应不使用冲突的东西?