Skip to content
This repository has been archived by the owner on Nov 8, 2017. It is now read-only.

Better support for mapping multiple keys #11

Open
marcbourlon opened this issue Mar 6, 2012 · 2 comments
Open

Better support for mapping multiple keys #11

marcbourlon opened this issue Mar 6, 2012 · 2 comments

Comments

@marcbourlon
Copy link

Is there a way to retrieve THE key pressed in case of single key? Because I'm not sure I wouldn't interfere with jwerty events, I'm trying to use jwerty for all my keys management. In which case, it happens I need to get the key pressed. How can I? I can do "if jwerty.is('x')", but it can be tedious.

@keithamus
Copy link
Owner

At current there is no "easy" way to do mass key bindings, other than using jwerty.is.

I have been considering the issue of mass-keybindings though, before this issue. My proposal is to allow an object mapping of keys to functions, allowing you to do something like this:

jwerty.key('myinput', {

    'ctrl+shift+a': false,
    'ctrl+shift+x': function () { console.log('ctrl shift x'); },
    'ctrl+shift+p': myFunction

});

However for repetitive tasks, that mostly do the same thing with a few minor exceptions, this doesn't really improve anything.

I'd like to see your use code though, how you're using it and what you think would improve the terseness.

@marcbourlon
Copy link
Author

HI Keith,

Thanks for the answer. While posting the issue, I thought that maybe I was not doing things optimally.
I'm doing a webapp, in which I use key combos (and for this, jwerty just rocks), but also single keypresses. I don't feel comfortable at adding my own keydown events, so I had to do it to detect single dead keys, as posted in another issue (how, with jwerty, would you use a dead key to enable a specific mode of your app? Like: normal mouse action is drawing, but if I press Ctrl, same mouse action will result in moving elements? I need a keydown and a keyup callbacks, and as of now, had to do with my own (crappy) code. Though this is another issue, it also comes to the fact I need to "complete" Jwerty, which is a bit less elegant for me.
As for the current issue, here's my need: I use the same callback for two keys (v and h namely), and use the key as an object property, to make it simple.
I have something like:

Jwerty.key('v/h', myCallback);

function myCallback(e) {
var key=Key.getKey(e);

MyObject[key] = "foobar";
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants