Using JavaScript or jquery i want to capture only ctrl+left mouse click event only to show a popup. Want to capture only this combination anything else with ctrl key should not be fired.
Asked
Active
Viewed 1,571 times
1
-
Possible duplicate of [How to detect control+click in Javascript from an onclick div attribute?](http://stackoverflow.com/questions/16190455/how-to-detect-controlclick-in-javascript-from-an-onclick-div-attribute) – Liam Nov 18 '16 at 14:59
2 Answers
2
The click
event has a ctrlKey
property. If it's true
the ctrl-key is being pressed. Example:
<button id="mybutton">click me + ctrl</button>
<script>
document.getElementById("mybutton").addEventListener("click", function () {
alert(event.ctrlKey ? "ctrl key pressed" : "ctrl key not pressed");
});
</script>

Halcyon
- 57,230
- 10
- 89
- 128
-
OK. Will try & update. I guess these code will be fired even if i press ctrl+shift+left mouse click? – jinish shah Nov 18 '16 at 15:03
-
-
tried the above code but it gets fired even if i use ctrl + shift + left mouse click. I just want ctrl + click event not any other combination with ctrl. – jinish shah Nov 21 '16 at 05:54
2
Capture the click event and check if ctrl is down. easy!
$("#div").click(function(event) {
if (event.ctrlKey) {
// ctrl + click is pressed
}
});

Pankaj Patidar
- 71
- 5
-
tried the above code but it gets fired if i use ctrl + shift + left mouse click. I just want ctrl + click event not any other combination with ctrl. – jinish shah Nov 21 '16 at 05:50