本文介绍了是否有可能在dblclick事件中检测到ctrl键状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是Google地图API版本3.我希望我的双击事件处理程序按如下方式工作:
google .maps.event.addListener(map,'dblclick',function(e){
if(/ * ctrl is pressed * /){
doSomething(e)
} else {
doSomethingElse(e)
}
});
它看起来事件处理程序只提供一个MouseEvent,它不包含有关键盘状态的信息。我需要LatLng信息,所以我怀疑我可以使用JQuery的事件处理。
我在这里运气不好吗?
解决方案
您可以缓存控制键状态
var ctrlPressed = false;
函数cacheIt(event){
ctrlPressed = event.ctrlKey;
}
document.onkeydown = cacheIt;
document.onkeyup = cacheIt;
现在, ctrlPressed
应始终反映是或不是控制键关闭。
I am using Google maps API version 3. I would like my double click event handler to work as follows:
google.maps.event.addListener(map, 'dblclick', function(e) {
if (/* ctrl is pressed */) {
doSomething(e)
} else {
doSomethingElse(e)
}
});
It looks the the event handler only provides a MouseEvent which does not contain information about the keyboard state. I need the LatLng information so I doubt that I can use JQuery's event handling.
Am I out of luck here?
解决方案
You could just cache the control key state
var ctrlPressed = false;
function cacheIt(event) {
ctrlPressed = event.ctrlKey;
}
document.onkeydown = cacheIt;
document.onkeyup = cacheIt;
Now, ctrlPressed
should always reflect whether or not the control key is down.
这篇关于是否有可能在dblclick事件中检测到ctrl键状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!