To implement the Ctrl / Alt / Shift detection, you can use the properties event.ctrlKey, event.altKey, and event.shiftKey in many event types.
This seems to work ok for Keyboard Events such as keydown / keypress / keyup.
For drag events though, there is a problem I managed to reproduce that happens ONLY in Safari browser (MAC OS).
I provide the script below. The problem is that, when I press Shift key while dragging the element, in all browsers the event.shiftKey gives "true" value. In Safari (tested on 14.01) this value is always false.
document.addEventListener("dragover", (event) => {
var shiftKey = event.shiftKey;
document.getElementById("div1").innerHTML = "<br>SHIFT pressed? " shiftKey;
}, false);
<div id="drag1"draggable="true">DRAG THIS TEXT WITH / WITHOUT PRESSING SHIFT KEY<div>
<div id="div1"></div>
CodePudding user response:
