Questions tagged [mousetrap]

Mousetrap is a JavaScript library for handling keyboard shortcuts

Official Links

36 questions
16
votes
2 answers

Mousetrap.bind is not working when field is in focus?

I am using Mousetrap for create keyboard shortcuts, it was not working when any fields in focus. This is the link for view demo http://davidwalsh.name/keyboard-shortcuts from where i get the code. when i use to call Mousetrap.bind('ctrl+m', function…
Jagan Akash
  • 559
  • 5
  • 26
14
votes
2 answers

Using mousetrap on a specific element?

I am using the Mousetrap javascript library and am wanting to capture input on a specific element. The scenario is I have a textbox for username and password which KnockoutJS binds to then when a button is pressed an ajax request is made to login…
Grofit
  • 17,693
  • 24
  • 96
  • 176
10
votes
2 answers

A method to manage keyboard shortcuts in react

Keyboard shortcuts are a bit tricky to manage in web applications. consider a Widget component. I want to be able to focus certain elements, and run functions on this component, based on keyboard shorcuts. class Widget extends React.Component { …
Stepan Parunashvili
  • 2,627
  • 5
  • 30
  • 51
6
votes
1 answer

How to test events created with mousetrap in react using jest

I am writing an application in react which uses mousetrap. I want to know how the events of mousetrap can be tested in jest. I want to see whether a component function is being called when I click left arrow. I am not able to simulate this event in…
prasadmsvs
  • 1,621
  • 4
  • 18
  • 31
6
votes
2 answers

Accessing mutable variable in an event closure

I am trying to use the mousetrap Javascript plugin to handle some key strokes in a similar fashion, so I thought to code them up as follows: var keys = [ 'b', 'i', 'u']; for (var i=0; i < 3; ++i) { var iKey = keys[i]; var…
jedierikb
  • 12,752
  • 22
  • 95
  • 166
4
votes
1 answer

Importing Mousetrap in React project - Cannot read property 'bind' of undefined

I'm trying to import mousetrap into a react project for some simple keyboard bindings. I installed Mousetrap via yarn. I don't have any errors importing, but the Mousetrap library object is undefined when I try to use it. This is from my main…
3
votes
0 answers

Angular2: Shortcut keys using HostListener vs Mousetrap

I am working on an Angular2 project wherein I want to incorporate Shortcut keys for various functionalities. I am confused between two approaches. One is to create shortcuts by using HostListener as below : @HostListener('document:keydown',…
harsrawa
  • 422
  • 5
  • 18
3
votes
0 answers

Launching bootstrap modal from data-keybinding using rails mousetrap gem

I am wondering if anyone knows whether the mousetrap gem for creating keybindings has the ability to launch a bootstrap modal dialog. As it stands, when I use 'link_to' to launch a modal such as: <%= link_to "Insert", new_item_path, remote:…
panagioti
  • 426
  • 4
  • 14
2
votes
1 answer

Mousetrap.bindGlobal is not a function

I installed Mousetrap through npm and have been trying to get Mousetrap.bindGlobal to work but this is the error it gives me Uncaught TypeError: mousetrap__WEBPACK_IMPORTED_MODULE_13__.bindGlobal is not a function This doesn't make sense because…
user5735224
  • 461
  • 1
  • 7
  • 16
2
votes
0 answers

AngularJS tabs and hotkeys combination

I am trying to use the hotkeys to change the tabs in AngularJS. I am new to AngularJS but i am sure it should be as simple as the code below. So when a hotkey is pressed, it is unable to change the tab activeness. It is basically doing nothing for…
Sam
  • 31
  • 4
1
vote
0 answers

How can I detect when a Mousetrap input is NOT being used?

I'm developing an app that uses text inputs. I've added Mousetrap to my codebase to utilise shortcuts and it works as expected. The issue I face: The regular keyup function also fires when the mouse trap function is called. I would like to only fire…
Moe-Joe
  • 1,012
  • 3
  • 15
  • 27
1
vote
2 answers

Focusing input field with Mousetrap.js - but input field also pastes the hotkey as value?

Have a look at the following example. I have enhanced the official example here with some Mousetrap functionality. So whenever somebody presses alt+1, the first input field will focus, whenever somebody presses alt+2 the second input field will be…
R. Kohlisch
  • 2,823
  • 6
  • 29
  • 59
1
vote
2 answers

Dynamically set Mousetrap.bind() key combinations from an object

I'm getting back data from our backend that contains information about keyboard shortcuts. This is a dumbed down version of what I will receive: { code: "r", message: "test R" }, { code: "s", message: "test S" }, { code: "c", message:…
Mahogany
  • 509
  • 4
  • 17
1
vote
1 answer

Moustrap node.js; Uncaught TypeError: callback is not a function

I have recently started using electron to create an app to compose music on for free. Unfortunately, while trying to set global keyboard shortcuts for it using mousetrap, I got the error Uncaught TypeError: callback is not a function. When I use…
1
vote
2 answers

Focus on bootstrap-tokenfield input

I would like to have focus on the tokenfield input field when the modal shows up. Currently it's focused only if I click on the input field in the modal. https://jsfiddle.net/csisanyi/h19Lzkyr/12/ I tried to add the following code …
Csisanyi
  • 669
  • 4
  • 16
1
2 3