Skip to content

Instantly share code, notes, and snippets.

@arjshiv
Last active July 2, 2018 10:48
Show Gist options
  • Save arjshiv/8567d38689d322a60eb9 to your computer and use it in GitHub Desktop.
Save arjshiv/8567d38689d322a60eb9 to your computer and use it in GitHub Desktop.
jQuery event handler - Detect control click (Ctrl+click) on Windows/ command + click (Cmd+click) on Mac
function clickHandler (event) {
if (event.ctrlKey || event.metaKey) {
//ctrlKey to detect ctrl + click
//metaKey to detect command + click on MacOS
executeCtrlClickActionHere();
} else {
executeRegularClickActionHere();
}
};
@dougblackjr
Copy link

I know this is older, but it just got me where I was going. Thank you!

@gandhirahul
Copy link

Why do you need to read the event.ctrlKey?
According to MDN, MouseEvent.metaKey is quite enough.

screen shot 2018-07-02 at 11 47 05

https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/metaKey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment