Closed
Description
So I really like Mousetrap. But it only captures window keypress events.
I'd like to add most of its aliases to the key
filter, but I can't see a tidy way to do it.
You've got this private dictionary in here:
/**
* A special filter that takes a handler function,
* wraps it so it only gets triggered on specific
* keypresses. v-on only.
*
* @param {String} key
*/
var keyCodes = {
enter : 13,
tab : 9,
'delete' : 46,
up : 38,
left : 37,
right : 39,
down : 40,
esc : 27
}
exports.key = function (handler, key) {
if (!handler) return
var code = keyCodes[key]
if (!code) {
code = parseInt(key, 10)
}
return function (e) {
if (e.keyCode === code) {
return handler.call(this, e)
}
}
}
I wonder if it would be reasonable to have a registerKeyCode({alias1:code1,alias2,code2,etc}) method since it seems like something people might want to extend often.
Metadata
Metadata
Assignees
Labels
No labels