hotkeys-js
hotkeys-js copied to clipboard
Ability to allow hotkeys on input fields
Love the library, for the longest time I have been using jquery.keys.js, nice and simple, but it's a jquery plugin.
One of the features of jquery.keys.js (https://github.com/jollytoad/jquery.keys/blob/ondemand/src/keys.core.js) is that any keys I define are useable anywhere on the page, including input fields, the other advantage of it (but this is likely because it's a jquery plugin) is that I can define the keys on the document level or on an element level (such as a bootstrap 4 modal).
Problem with your awesome library is that if I am in an input element (text, textarea, etc...) I can't use the hotkeys.
Is it possible for a way to bypass this?
As for the element level, I assume I can use the 'scope' for that? So when the bootstrap 4 modal opens, in the 'show' event, set the scope to 'modal' (for example), and then only keys defined for that scope will work?
@ray73864 INPUT
SELECT
TEXTAREA
default does not handle.
hotkeys('o, enter', {
scope: 'wcj',
element: document.getElementById('warpper'),
}, function(){
console.log('do something else');
});
Support element
options.
You can also use 'scope' to solve your problem.
I can't parse the last comment. Is it possible to make bound hotkeys trigger while an input field is focused?
I can't parse the last comment. Is it possible to make bound hotkeys trigger while an input field is focused?
I managed to do it using the filter functionality.
hotkeys.filter(function(e) { return true; });
It would be great to close this issue and link to a working example hosted on codesandbox.
Implemented with Vanilla JS, as it doesn't seem to be fixed.
document.addEventListener('keydown', (event) => {
if (event.key === "Escape") {
// do something.
}
});
I added this somewhere in the startup code to solve the issue
hotkeys.filter = (e:KeyboardEvent) => true;