hotkeys-js icon indicating copy to clipboard operation
hotkeys-js copied to clipboard

Ability to allow hotkeys on input fields

Open ray73864 opened this issue 5 years ago • 6 comments

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 avatar May 24 '19 08:05 ray73864

@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.

jaywcjlove avatar May 27 '19 15:05 jaywcjlove

I can't parse the last comment. Is it possible to make bound hotkeys trigger while an input field is focused?

mrozekma avatar Jul 23 '19 21:07 mrozekma

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; });

ray73864 avatar Jul 23 '19 21:07 ray73864

It would be great to close this issue and link to a working example hosted on codesandbox.

aleccool213 avatar Aug 19 '19 15:08 aleccool213

Implemented with Vanilla JS, as it doesn't seem to be fixed.

document.addEventListener('keydown', (event) => {
  if (event.key === "Escape") {
    // do something.
  }
});

himeyon avatar Dec 06 '21 06:12 himeyon

I added this somewhere in the startup code to solve the issue

hotkeys.filter = (e:KeyboardEvent) => true;

underdoeg avatar Dec 19 '21 23:12 underdoeg