ccampbell / mousetrap

Simple library for handling keyboard shortcuts in Javascript
https://craig.is/killing/mice
Apache License 2.0
11.69k stars 968 forks source link

ctrl+tab doesn't fire #507

Open donnydarko opened 3 years ago

donnydarko commented 3 years ago

I want to use ctrl+tab in my electronjs app. So it is not a browser to interrupt with tab changing shortcut. However when I'm inside a text area it doesn't fire at all. Other shortcuts without tab do. How do I bind the whole document ?

<script>
    Mousetrap.bind(['command+tab', 'ctrl+tab'], function() {
       alert('command tab or control tab);

        // return false to prevent default browser behavior
        // and stop event from bubbling
        return false;
    });
</script>
j-applese3d commented 3 years ago

From the documentation:

Text fields

By default all keyboard events will not fire if you are inside of a textarea, input, or select to prevent undesirable things from happening.

If you want them to fire you can add the class mousetrap to the element.


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