7

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
  • 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 Answers1

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)
    }
});
Andrew
  • 101
  • 1
  • 10
ry4nolson
  • 829
  • 4
  • 13