I would like to know when a user is pressing down the Shift key during mousemove.
The problem is that Windows doesn't trigger keydown event when pressing down Ctrl, Shift or Alt. Instead, the event is triggered on releasing the key. On Mac everything is working as expected, however (keydown is triggered when you press down the key)
About the same problem with mouse move events. The event.shiftKey will only be true after you've held down Shift and triggered a mousedown...
Are there any workarounds for this? Here's an example: https://jsfiddle.net/ecz0deqw/4/
document.onkeydown = function (e) {
addText('Key pressed: ' + e.key)
};
document.onmousemove = function (e) {
if(e.shiftKey)
addText('ShiftMove');
else {
addText('NoShift')
}
}
function addText(text) {
var newP = document.createElement("p");
newP.innerText = text;
document.body.insertBefore(newP,document.body.childNodes[0]);
}
Thanks / Eric
document.body
instead ofdocument
, and useaddEventListener()
to do so – Lennholmkeydown
spec, and the spec regarding "modifier keys", thekeydown
event should be raised. – user47589