我正在尝试创建键盘+鼠标单击快捷方式来执行代码。
在下面的示例中,当我单击鼠标按钮时,它将返回var mouseDown为1。
然后,如果mouseDown等于1并按下键盘键移位,我希望出现警报消息。
键盘+鼠标单击事件失败:
var mouseDown = 0;
document.onmousedown = function(e) {
if (e.which == 1) { //Left mouse button on Mac
mouseDown = 1;}
else {
mouseDown = 0;}
};
if (mouseDown == 1) {
document.onkeyup = function(e) {
if (e.which == 16) { //Shift key on Mac
alert("Shift + mouse was pressed");
mouseDown = 0;
}
};
}
仅鼠标单击事件有效:
document.onmousedown = function(e) {
if (e.which == 1) {
alert("Mouse was pressed");
}
};
仅Shift键事件有效:
document.onkeyup = function(e) {
if (e.which == 16) {
alert("Shift was pressed");
}
};
答案 0 :(得分:1)
使用此
0 */3 * * *