Mouse events (onclick) with modifiers shift, alt, ctrl and meta keys
All mouse events include the information about pressed modifiers keys.
event object have the following properties:
- ctrlKey
- shiftKey
- altKey
- metaKey (for MAC)
All above properties will be return the true or false value.
If user pressed the mouse button with the pressing ctrlKey than then ctrlKey property will return the true.
JS:
var btnClick = document.getElementById("btnClick"); btnClick.onclick = function (event) { if (event.ctrlKey && event.shiftKey && event.altKey) { alert("Button is pressed with the ctrl, shift and alt key."); } else if (event.ctrlKey && event.shiftKey) { alert("Button is pressed with the ctrl and shift key."); } else if (event.ctrlKey && event.altKey) { alert("Button is pressed with the ctrl and alt key."); } else if (event.shiftKey && event.altKey) { alert("Button is pressed with the shift and alt key."); } else if (event.ctrlKey) { alert("Button is pressed with ctrl key."); } else if (event.shiftKey) { alert("Button is pressed with shift key."); } else if (event.altKey) { alert("Button is pressed with alt key."); } else { alert("Only button is pressed."); } };