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) {
alert('CTRL+S COMBO WAS PRESSED!')
//run code for CTRL+S -- ie, save!
e.preventDefault();
}
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 by using this second example, 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.
I am a little late to the party but here is my part
In my case, I was looking for a keydown ctrl key and click event. My jquery looks like this:
Where "linkAccess" is the class name for some specific fields where I have a link and I want to access it using my combination of key and click.
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
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:You cannot use Ctrl+C by jQuery , but you can with another library which is shortcut.js
Live Demo : Abdennour JSFiddle