Organizational Research By

Surprising Reserch Topic

jquery keypress ctrlc or some combo like that

jquery keypress ctrlc or some combo like that  using -'jquery,javascript-events,keypress,keydown'

I'm trying to create shortcuts on the website i'm making. I know I can do it this way:

if(e.which == 17) isCtrl=true;
if(e.which == 83 && isCtrl == true) {
    //run code for CTRL+S -- ie, save!

But the example below is easier and less code, but it's not a combo keypress event:

$(document).keypress("c",function() {
  alert("Just C was pressed..");

So I wanna know if using this second example if I could do something like:

$(document).keypress("ctrl+c",function() {
  alert("Ctrl+C was pressed!!");

is this possible? i've tried it and it didn't work, what am i doing wrong.

asked Sep 9, 2015 by OctHLGT
0 votes

Related Hot Questions

6 Answers

0 votes

Another approach (no plugin needed) it to just use .ctrlKey property of the event object that gets passed in. It indicates if Ctrl was pressed at the time of the event, like this:

$(document).keypress("c",function(e) {
    alert("Ctrl+C was pressed!!");
answered Sep 9, 2015 by ReinaANBvhwd
0 votes

I am a little late to the party but here is my part

$(document).on('keydown', function ( e ) {
    // You may replace `c` with whatever key you want
    if ( e.ctrlKey && ( String.fromCharCode(e.which) === 'c' || String.fromCharCode(e.which) === 'C' ) ) {
        console.log( "You pressed CTRL + C" );
answered Sep 9, 2015 by Sha4777
0 votes

you cannot use "Ctrl+C" by jquery , but you can with another library which is shortcut.js

Live Demo : Abdennour JSFiddle

$(document).ready(function() {
shortcut.add("Ctrl+C", function() {
    $('span').html("أحسنت. لقد ضغطت على حرفي : Ctrl+C");
    shortcut.add("Ctrl+V", function() {
    $('span').html("أحسنت. لقد ضغطت على حرفي : Ctrl+V");
       shortcut.add("Ctrl+X", function() {
    $('span').html("أحسنت. لقد ضغطت على حرفي : Ctrl+X");

answered Sep 9, 2015 by AdalbertoACB
0 votes

Try the Jquery Hotkeys plugin instead - it'll do everything you require.

jQuery Hotkeys is a plug-in that lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination.

This plugin is based off of the plugin by Tzury Bar Yochay: jQuery.hotkeys

The syntax is as follows:

$(expression).bind(types, keys, handler); $(expression).unbind(types, handler);

$(document).bind('keydown', 'ctrl+a', fn);

// e.g. replace '$' sign with 'EUR'
// $('').bind('keyup', '$', function(){   
//      this.value = this.value.replace('$', 'EUR'); });
answered Sep 9, 2015 by LinShrader
0 votes

There is a plugin for Jquery called "Hotkeys" which allows you to bind to key down combinations.

Does this do what you are after?

Jquery HotKeys - Google Code

answered Sep 9, 2015 by DolCross
0 votes
" rel="nofollow" target="_blank">">

answered Sep 9, 2015 by CCPRonicqlmk