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
It is not necessary to store in a variable when the shift key is pressed and released. You can achieve what you are trying to to like this:
$('#selector').mouseover( function(e){ if (e.shiftKey) { console.log("the shift key is pressed"); } } );