Reputation: 891
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 defaults to the browser original (in this case find). If I click outside the input box, intended function is called by jquery.hotkeys.
What should I do if I want to get the uniform behaviour whether input is focused or not?
Upvotes: 2
Views: 2152
Reputation: 1092
You can give this a shot:
$(document).bind('keydown', function(e) {
if (e.ctrlKey && e.which == 70) {
$('#myid').focus();
return false;
}
});
The problem is, it's not using the plugin. So feel free to NOT mark this the answer even if it works for you as it does not answer the initial question IMHO.
Upvotes: 2
Reputation: 16577
Refer docs: https://github.com/jeresig/jquery.hotkeys#hotkeys-within-inputs
Hotkeys aren't tracked if the user is focused within an input element or any element that has contenteditable="true" unless you bind the hotkey directly to the element. This helps to avoid conflict with normal user typing. If you don't want this, you can change the booleans of the following to suit:
jQuery.hotkeys.options.filterInputAcceptingElements jQuery.hotkeys.options.filterContentEditable jQuery.hotkeys.options.filterTextInputs (deprecated, will be removed in a later version)
Upvotes: 0