Is there a way to with jQuery keyCode to detect Command + C? The keycode only sends one key, not the pressed combo. I'm looking to setup a binding to detect Command + C. I've seen some keyboard shortcut plugins but would like to avoid adding an additional library for one simple binding.
Asked
Active
Viewed 8,400 times
7
-
http://stackoverflow.com/questions/10655202/detect-multiple-keys-on-single-keypress-event-on-jquery – Banana Jun 28 '14 at 18:57
-
Are you trying to detect if the user is copying something? If so, Command + C detection would only work for Mac users. – Ronald Snew Jun 28 '14 at 19:50
1 Answers
22
you can check the ctrlKey
property of the event. (possibly metaKey
if it's on mac, not sure)
for Ctrl + C
$(document).on("keydown", function(e){
if (e.keyCode == 67 && (e.ctrlKey || e.metaKey)){
//it was Ctrl + C (Cmd + C)
}
});
-
2Using (e.ctrlKey || e.metaKey) adds Mac support. I confirm as well. Thanks. – Eugene Kardash Mar 07 '18 at 17:26