1

I use the Keydrown plugin, so this works nicely with letter keys:

kd.W.down(function () {
    //...
});

How can I assign the same function to lshift instead of W? (I don't know how to put here a keycode instead of letter).

And if possible, how can I select 2 keycodes and do something for lshift+W? (when both are pressed at the same time).

edit:

Seems the best and the most simple way to select any key by keycode is to edit the plugin itself - to edit the keycode list under the KEY_MAP. For example add:

,'LSHIFT': 16

to the list, and call kd.LSHIFT.down.

The question about lshift+W still remains - is it possible to put the 2 keycodes under the 1 name in this KEY_MAP list? (would be the best / simplest solution)

astx123
  • 85
  • 8
  • You might want to try js-hotkeys this might be a good reference http://stackoverflow.com/questions/593602/keyboard-shortcuts-with-jquery – johnny 5 Jul 18 '14 at 13:41

2 Answers2

0

So in the keydrown plugin edit the list under the KEY_MAP, for example add:

,'LSHIFT': 16

LSHIFT+W can be achieved in this way:

kd.W.press(function () {
    kd.LSHIFT.press(function () {
        //...
        console.log();
    });
    //optional...
    console.log();
});
kd.W.up(function () {
    kd.LSHIFT.press(function () {
        console.clear();
    });
    console.clear();
});

down can be used instead of press depending on desired behavior. To bind / unbind keys in more complex cases, use the Keydrown plugin instructions.

astx123
  • 85
  • 8
0

I'm the developer of Keydrown. Sorry I didn't see this until now! kd.map.js supports the generic "shift" keycode (16), but I'm not familiar with how that relates to the keycode for the left shift button specifically (somebody please feel free to chime in and clarify).

Anywho, if adding 'LSHIFT': 16 to the map works as desired, here's is what I'd recommend for achieving the "left shift + W" functionality:

kd.LSHIFT.down(function () {
  if (kd.W.isDown()) {
    // Your code here
  }
});

isDown is a newer Keydrown API that was introduced after this question was asked, I believe.

I hope this helps. If the LSHIFT keycode works consistently across the supported browsers, please submit a Pull Request.