Example 1 — Log on mousemove (MDN)
Show whether Control is held while the cursor moves.
const log = document.querySelector("#log");
window.addEventListener("mousemove", function (e) {
log.textContent =
"The ctrl key was pressed while the cursor was moving: " + e.ctrlKey;
}); How It Works
- Listen for
mousemove. Fires as the pointer moves. - Read
e.ctrlKey. Boolean for Control at that moment (MDN). - Update the log. Easy live feedback.
- Works well on Mac too. Unlike Control+click, move events still see Control.

