Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript or jQuery event handlers for "Ctrl"/"Shift" + mouse left button click

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.

like image 546
Anton Avatar asked Mar 21 '10 00:03

Anton


People also ask

Which jQuery method is used to attach a handler to an event?

bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to . bind() occurs.

What is a handler in jQuery?

A handler is something that is done when an event occurs. Like when you click a button, what occurs because the button was clicked is the handler. It handles the given event. Here is a list of events that will have handlers for jquery.


1 Answers

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.

like image 92
Nick Craver Avatar answered Sep 24 '22 08:09

Nick Craver