Questions tagged [jquery-hotkeys]

jquery.hotkeys plugin lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination.

jquery.hotkeys plugin lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination.


The syntax is as follows:

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

$(document).bind('keydown.ctrl_a', fn);

// e.g. replace '$' sign with 'EUR'
$('input.foo').bind('keyup.$', function(){
  this.value = this.value.replace('$', 'EUR');
});

Supported types are keydown, keyup and keypress

If you want to use more than one modifiers (e.g. ctrl+alt+z) you should define them by an alphabetical order e.g. alt_ctrl_z

Hotkeys aren't tracked if you're inside of an input element (unless you explicitly bind the hotkey directly to the input). This helps to avoid conflict with normal user typing.

All keys that have special meaning in RegExp strings (.+*?^${}/'#) can't be removed by using the namespaced event until this jQuery bug get's fixed: http://bugs.jquery.com/ticket/11458 the colon (.) will never work (even if bug is fixed) since it is used to separate multiple namespaces.
To remove them you will need to remove events to the whole event type:

// won't work
$('#foo').unbind('keyup.$');
$('#foo').unbind('keyup.+');

//will work
$('#foo').unbind('keyup');
$('#foo').unbind('keyup.a');
$('#foo').unbind('keyup.ctrl_s');

Works with jQuery 1.4.2 and newer.

It is known to be working with all the major browsers on all available platforms (Win/Mac/Linux)

  • IE 6/7/8
  • FF 1.5/2/3
  • Opera-9
  • Safari-3
  • Chrome-0.2

Firefox is the most liberal one in the manner of letting you capture all short-cuts even those that are built-in in the browser such as Ctrl_t for new tab, or Ctrl_a for selecting all text. You can always bubble them up to the browser by returning true in your handler.

Others, (IE) either let you handle built-in short-cuts, but will add their functionality after your code has executed. Or (Opera/Safari) will not pass those events to the DOM at all.

So, if you bind Ctrl_Q or Alt_F4 and your Safari/Opera window is closed don't be surprised.


Resources

20 questions
6
votes
4 answers

js-hotkeys - how to bind to the ? question mark

I've been using js-hotkeys for a while, love it. I'd now like to bind to the ? key, but that doesn't appear to be supported. Anyone know why and how to bind to the ? question mark? $(document).bind('keydown', '?',function (evt) { …
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
4
votes
2 answers

Can't override ctrl+s in Firefox using jQuery Hotkeys

I'm using the jQuery Hotkeys plugin: http://code.google.com/p/js-hotkeys/ Here is the code i'm using: $(document).bind('keydown', 'Ctrl+s', function(event) { alert('saving?'); return false; }); In Chrome it works fine and the Ctrl+s default…
Talon
  • 4,937
  • 10
  • 43
  • 57
2
votes
1 answer

Javascript - keyup event firing multiple times

I am using hotkeys plugin to add handlers to key events. I have made an image slider, where I go through cover images of magazines. I have first made a script where the user can go through covers of a magazine, with a click on navigation…
Leff
  • 1,968
  • 24
  • 97
  • 201
2
votes
2 answers

jQuery.HotKeys keybinding while input is focused

I am using jquery.hotkeys for implementing keyboard shortcuts. My code: $(document).bind('keydown', 'Ctrl+f', function () { $('#myid').focus(); return false; }); This works fine. But if any input is in focus, the keystroke…
Vivekanand P V
  • 861
  • 3
  • 13
  • 27
2
votes
1 answer

jquery hotkeys not working in current browsers?

I have not used jquery.hotkeys.js in a while, but I cant seem to get even the most basic test to work in any current browsers. Using Ver 0.8 I also tried with other versions of jQuery but stuck with 1.4.2 for testing since that was what John Resig…
Alex
  • 1,535
  • 2
  • 16
  • 26
2
votes
1 answer

How to make CTRL+N work on Hotkeys JQuery plugin?

I am using the following plugin : Link I believe this is the most used one from the JQuery community: I am having problem trying to make ctrl+N work, see the code below: $(document).bind('keydown', 'ctrl+N', function () { alert(""); …
RollRoll
  • 8,133
  • 20
  • 76
  • 135
2
votes
2 answers

jQuery hotkeys plugin uses bind

I'm using the jQuery hotkeys plugin, written by John Resig (Mr jQuery). It uses bind, however, and bind is now replaced by on as noted in the official jQuery API. The standard code is: $(document).bind('keyup', 'alt+a', function(evt){...}); I…
Nick
  • 5,995
  • 12
  • 54
  • 78
1
vote
0 answers

How to make the enter key do the tab key function for form elements

I am using jQuery Hotkey plugin https://github.com/jeresig/jquery.hotkeys , I want to move to other input boxes on keydown Enter instead of Tab which is default behaviour. But somehow I can't make it go. Can anyone please help me how to sort that,…
1
vote
0 answers

How to set keyboard shortcuts common to both windows and mac using jquery

I had an web application which had piece of code for shortcuts which is working fine for windows in both chrome and firefox. How can i extend this to Mac machine for both chrome and firefox. Code in windows $(document).bind("keydown","Ctrl+s",…
CNKR
  • 568
  • 5
  • 19
1
vote
1 answer

Using Hotkeys to navigate tabs

How can I navigate between different tabs using shortcut keys implemented using hotkey from the following : https://github.com/jeresig/jquery.hotkeys .
H Dindi
  • 1,484
  • 6
  • 39
  • 68
1
vote
2 answers

document keydown bind not working for input field

I have been using jquery hotkeys plugin from jeresig's hotkey. Shortcuts work fine when the document is in focus, but when the focus is in input fields, the shortcuts are not working. I have used $(document) or $(document).find('input') for binding.…
nexuscreator
  • 835
  • 1
  • 9
  • 17
1
vote
1 answer

Latest version of jQuery hotkeys plugin doesn't accept characters unless using keypress

I downloaded the latest version of the jQuery plugin here. I noticed that it doesn't work if I bind it using keydown and pass in something with a character like 'ctrl+u'. I found that this piece of code seems to be preventing it. character =…
griztown
  • 121
  • 3
  • 13
1
vote
3 answers

JS bind a keyboard shortcut to a function

function initKeys() { $(document).bind("keydown", "U", LoadPlayer); } window.onload = initKeys; I want to execute the function 'LoadPlayer' on pressing the u key. What I'm getting is that for any pressed key the 'LoadPlayer' is executed. The…
Sanich
  • 1,739
  • 6
  • 25
  • 43
1
vote
1 answer

Why is the JQuery hotkeys triggering more than once for shortcut

I have the following code: each shortcut is for different functionality, but when I use ctrl+r it displays the alert 4 times. Am I doing anything wrong? the code below looks fine for me... I'm using chrome, but I don't think it…
RollRoll
  • 8,133
  • 20
  • 76
  • 135
0
votes
3 answers

JQuery Hotkeys - binding to multiple alphanumeric character combinations

I am using the latest version of JQuery hotkeys. The plug-in is fantastic and, in the main, does exactly what I need it to do. However, I would like to bind to a combination of keys such as "A+H", for example: jQuery(document).bind('keydown', 'a+h',…
oscarH
  • 1
  • 1
1
2