views:

322

answers:

2

Is it possible to handle such events as: "ctrl" + mouse left button click; "shift" + mouse left button click; "alt" + mouse left button click by using JavaScript/jquery(or other framework).

If it is possible, please give a code example for it.

+6  A: 

You can do something like this (jQuery for the click handler, but any framework works on the part that matters):

$(selector).click(function(e) {
  if(e.shiftKey) {
    //Shift-Click
  }
  if(e.ctrlKey) {
    //Ctrl+Click
  }
  if(e.altKey) {
    //Alt+Click
  }
});

Just handle whichever you want inside an if inside the click handler like I have above.

Nick Craver
A: 

If you use JQuery plugin called hotkeys you can handle the special keys below.

$(document).bind('keydown', 'Ctrl+c', fn);
Dhaval