In an onclick handler, how can I detect whether shift was pressed?

You can look at the click event’s shiftKey property.

window.addEventListener("click",
  function(e) {
    if (e.shiftKey) console.log("Shift, yay!");
  },
  false);
<p>Click in here somewhere, then shift-click.</p>

Leave a Comment