Update
After reading your comment and rereading your question things already make another sense.
Assuming you want to allow the selection of multiple options without the user using the ctrl key, you can achieve this in the following way:
JSFiddle Demo
var multiSelect = {};
function init() {
var s = document.getElementsByTagName('select');
for (var i = 0; i < s.length; i++) {
if (s[i].multiple) {
var n = s[i].name;
multiSelect[n] = [];
for (var j = 0; j < s[i].options.length; j++) {
multiSelect[n][j] = s[i].options[j].selected;
}
s[i].onclick = changeMultiSelect;
}
}
}
function changeMultiSelect() {
var n = this.name;
for (var i=0; i < this.options.length; i++) {
if (this.options[i].selected) {
multiSelect[n][i] = !multiSelect[n][i];
}
this.options[i].selected = multiSelect[n][i];
}
}
window.onload = init;
See this answer from @Vedmant on SOEN dated 16 Jan 2013.
Original Response
The original response was given on the understanding that it was intended to detect that the ctrl key was in use when there was a click
with the mouse. >
There is no way to simulate the use of a particular key without the user actually using it.
Your example:
event.ctrlKey = true;
Do not do anything rigorously, it does not really impact the ctrl key or the event associated with its use.
Although it had some effect, it would not be easy to make this a viable solution, since in MAC for example, the cmd key is used.
See this answer from @Juhana on SOEN dated Feb 22, 2012
Solution
Dropping your initial approach to its unfeasibility, you can be aware of the use of this key in conjunction with the mouse click.
For this you apply the click
event to your element and verify that you have the ctrl key clicked too:
JSFiddle Demo
$(selector).click(function(e) {
if(e.ctrlKey) {
//Ctrl+Click fazer algo
}
});
See this answer from @Nick Craver ♦ in SOEN dated 21 Mar 2010.