1

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.

jinish shah
  • 65
  • 2
  • 11
  • 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 Answers2

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
2

Capture the click event and check if ctrl is down. easy!

$("#div").click(function(event) {
 if (event.ctrlKey) {
   // ctrl + click is pressed
 }
});
  • 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