How can I capture keyboard events (keypress,keyup, ) while dragging an image,bookmark
$(element).bind("dragover", func开发者_运维百科tion () {
$(document).keypress(function(e){
console.log(e.which + ": " + String.fromCharCode(e.which));
});
}
I cannot detect the keypress events once I start dragging. Is there another way to detect the keyboard inputs?
Events like dragging an image, bookmark (which are not explicitly set to be draggable) and other modal dialogs like alert()
and confirm()
are known to "pause" the the event listening activity as well as any timers that are running in that context.
That said, you might want to look into the setCapture()
method.
It turns mouse capture on for a specified element.
In other words, it redirects all mouse events to a specified DOM element until a call to .releaseCapture()
is made.
It is traditionally used in drag-drop scenarios.
Passing true
as parameter will let current element (if a container) capture all mouse events. i.e. cause the parent container to intercept events.
Passing false
will let mouse events reach their intended targets before bubbling.
These below links are a good starting-point..
http://blog.stchur.com/category/advanced-javascript/page/2/
http://javascript.gakaa.com/object-setcapture-4-0-5-.aspx
Binding the event didnt work...tried with keypress,keydown,keyup SetCapture is just for IE, but I need it to be compatible with Chrome. I am trying something with addEventListener, but I am stuck with it... If I find the solution, I will post it
精彩评论