使用javascript(jquery okay),如何在shift +选项+命令+左键单击对象时触发事件?
$(document).on('keypress', function(e) {
if( e.keyCode == 224 && e.keyCode == 16 && e.keyCode == 18 ){
console.log('keys pressed');
}
});
看起来像这样的东西应该用于记录密钥(但它根本不用^^)而且,我如何跟踪点击?
谢谢!
答案 0 :(得分:1)
试试这个:
现场演示 (适用于Mac OS):http://jsfiddle.net/NDuDZ/2/
代码:
//Combination: Shift+Option+Command+LeftClick
//Shift Firefox, Safari, Chrome, Opera keyCode: 16
//Option Firefox, Safari, Chrome, Opera keyCode: 18
//Command Firefox keyCode: 224
//Command Chrome, Safari keyCode: 91
//Command Opera keyCode: 17
var isOption = false;
var isCommand = false;
var isLeftClick = false;
$(document).on('keyup', function(e){
if(e.which == 91 || e.which == 224 || e.which == 17) isCommand = false;
if(e.which == 18) isOption = false;
});
$(document).on('click', function(e){
isLeftClick = true;
});
$(document).on('keyup', function(e){
if(e.which == 91 || e.which == 224 || e.which == 17) isCommand = true;
if(e.which == 18) isOption = true;
if(e.which == 16 && isOption && isCommand && isLeftClick) {
alert('Shift+Option+Command+LeftClick invoked!');
e.preventDefault();
}
});