angular-hotkeys
angular-hotkeys copied to clipboard
Can't add separate 'keydown' and 'keyup' actions for the same key
The code below should print both DOWN and UP, but only prints UP.
hotkeys.bindTo($scope).add({
combo: 'a', action: 'keydown', callback: function() {
console.log("DOWN");
},
combo: 'a', action: 'keyup', callback: function() {
console.log("UP");
}
});
seems like a bug in Mousetrap.
I opened https://github.com/ccampbell/mousetrap/issues/284
+1 .. would be great for things like multiple select:
hotkeys.bindTo($scope).add({
combo: 'command',
description: 'Multiple Select on',
action: 'keydown',
callback: function(event, hotkey) {
console.log('cmd down');
$scope.multipleSelect = true;
}
}).add({
combo: 'command',
description: 'Multiple Select off',
action: 'keyup',
callback: function(event, hotkey) {
console.log('cmd up');
$scope.multipleSelect = false;
}
});
maybe related to https://github.com/ccampbell/mousetrap/issues/304
I smell something when it comes to key sequence (not combos) in Mousetrap, not gonna dive into their code again but it could possibly fire the event twice. Not sure but worth a check.
This works fine in Mousetrap when angular-hotkeys is taken out of the equation, as you can see here.
The actual issue was introduced in this pull request:
// no duplicates please
_del(combo);
This deletes all previously assigned combinations matching the current one being binded, thus removing others even if they have a different action.
@devonzara A great example of where we should use the callback reference to search for dedup, instead of removing everything previously assigned.
That, or just pass the action as a second parameter through to the Mousetrap method as I've done here. :)
It actually works if I add the 'keyup' action before I add the 'keydown' action.