English 中文(简体)
是否可以检测dblclick事件上的ctrl键状态
原标题:Is it possible to detect ctrl key state on dblclick event

我使用的是谷歌地图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;
function cacheIt(event) {
    ctrlPressed = event.ctrlKey;
}
document.onkeydown = cacheIt;
document.onkeyup = cacheIt;

现在,ctrlPressed应该始终反映控制键是否按下。

问题回答

当缓存按键时,我总是将一个函数绑定到窗口对象的模糊事件,该事件会清除任何缓存的按键。否则,如果窗口失去焦点,则会卡住关键帧。

下面是一个使用jQuery的示例:

$(window).blur( function () {
  // Clear cached key presses here
})




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签