Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Command + C keypress [duplicate]

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.

like image 371
AnApprentice Avatar asked Jun 28 '14 18:06

AnApprentice


1 Answers

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)
    }
});
like image 53
ry4nolson Avatar answered Oct 02 '22 17:10

ry4nolson