Mousetrap.bind not working when field is in focus?

I use Mousetrap to create keyboard shortcuts, it did not work when any fields are in focus. This is the link to view the demo http://davidwalsh.name/keyboard-shortcuts , where I get the code from. when i use to call

Mousetrap.bind('ctrl+m', function () { var button = $('[data-action="next-page"]'); if (button.length) { button[0].click() } }); 

like this, it doesn’t work when the mouse is pointing in a text box or drop down list, etc. Can anyone give a solution for me. Thanks in advance.

+7
jquery jquery-ui keyboard-shortcuts
source share
2 answers

By default, the mouse disables shortcuts when the focus is in the input fields, drop-down list, etc. If your problem is related to only one field, include the mousetrap class in it. If you want to disable all scripts, try the following code

 Mousetrap.stopCallback = function () {    return false; } 

This will overwrite the original behavior and resolve shortcuts in any field of the screen.

+15
source share

If you use input elements or textarea or select, you must define a mousetrap class:

 <textarea name="message" class="mousetrap"></textarea> 

See the "Text Fields" section in the white paper https://craig.is/killing/mice

0
source share

All Articles