Reputation: 39
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
Upvotes: 1
Views: 1939
Reputation: 4132
Is your Windows machine a VM? Parallels (at least) does funny stuff with the modifier keys.
Under Actions
> Configure
go to the Mouse & Keyboard
tab. Next to the Keyboard
label, choose Optimize for games
.
Underneath that option Parallels states: "When the keyboard is optimized for games, modifier keys become more responsive."
Upvotes: 1