I\'m trying to detect whether the shift key is being pressed while the cursor is moved over a particular element. The function fires, but only after I click on another
check this on the keypress event:
$(document).keypress(function (e) {
if(e.shiftKey) {
pressed = true; // pressed is a global varialbe. Be carefull of the scope
}
}
then on the keyup:
$(document).keyup(function(event){
pressed = false;
});
then do:
$("#selector").mouseover(function(e){
if(pressed) {
console.log("the shift key is pressed");
}
});
or the other way around :
$("#selector").mouseover(function(e){
isover = true;
});
and
$(document).keypress(function (e) {
if(e.shiftKey) {
alert("do something")
}
}