javascript 确定在 mousedown 事件期间是否按下了 Shift 键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12518741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:25:19  来源:igfitidea点击:

Determine if Shift key is pressed during mousedown event

javascriptd3.js

提问by Cristian G

Is it possible to determine whether the Shift key is pressed during a mousedown d3.event? if possible could show me a way to do this, try looking in the API, but could not find something useful

是否可以确定在 mousedown d3.event 期间是否按下了 Shift 键?如果可能的话可以告诉我这样做的方法,请尝试查看 API,但找不到有用的东西

回答by A.M.K

You should be able to use something like this:

你应该能够使用这样的东西:

d3.select(window).on("click", function() {
    if (d3.event.shiftKey) {
        alert("Mouse+Shift pressed");
    }
});

Demo: http://jsfiddle.net/SO_AMK/NTGKG/1/

演示:http: //jsfiddle.net/SO_AMK/NTGKG/1/

回答by ReHa

Maybe it is necessary to use:

也许有必要使用:

if (d3.event.sourceEvent.shiftKey) {
  console.log("shift pressed");
}