JavaScript: Check if CTRL button was pressed
Try looking in the event object.
e.g.
document.body.onclick = function (e) {
if (e.ctrlKey) {
alert("ctr key was pressed during the click");
}
}
<p>Click me, and sometimes hold CTRL down!</p>
I did it using cntrlIsPressed global flag; also takes care of select all option using Control + A
// Check whether control button is pressed
$(document).keydown(function(event) {
if (event.which == "17")
cntrlIsPressed = true;
else if (event.which == 65 && cntrlIsPressed) {
// Cntrl+ A
selectAllRows();
}
});
$(document).keyup(function() {
cntrlIsPressed = false;
});
var cntrlIsPressed = false;
I use this and works fine
<a href="" onclick="return Details(event)" ></a>
function Details(event) {
if (event.ctrlKey) {
alert('Ctrl down');
}
}