Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to bind key combination ctrl+x+return in jquery

Is there any way to catch key combination ctrl+x+return in jquery(or javascript), such that if user presses this key combination, a function is called. I tried using the jquery hotkeys plugin, but that didn't worked.

like image 531
user1304683 Avatar asked Mar 31 '12 09:03

user1304683


People also ask

How do you bind a function to click an event in jQuery?

jQuery bind() MethodUse the on() method instead. The bind() method attaches one or more event handlers for selected elements, and specifies a function to run when the event occurs.

Which jQuery keyword should be used to bind an event to an element?

bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to . bind() occurs.

How do you check Enter key is pressed in jQuery?

To check if an “enter” key is pressed inside a textbox, just bind the keypress() to the textbox. $('#textbox'). keypress(function(event){ var keycode = (event. keyCode ?

What is jQuery shortcut?

jQuery Hotkeys lets you watch for keyboard events anywhere in your code supporting almost any key combination. To bind Ctrl + c to a function ( f ), for example: $(document). bind('keydown', 'ctrl+c', f);


1 Answers

You may find using KeyboardJS to be a better solution. Its dam simple to use. Here are docs;

KeyboardJS.on('ctrl + x + enter', function() {
    //do stuff on press
}, function() {
    //do stuff on release
});

Also, if you want to force pressing ctrl before x or enter you can do this instead

KeyboardJS.on('ctrl > x + enter', function() {
    //do stuff on press
}, function() {
    //do stuff on release
});

http://robertwhurst.github.com/KeyboardJS/

like image 117
Robert Hurst Avatar answered Sep 22 '22 02:09

Robert Hurst