dmauro / Keypress

A keyboard input capturing utility in which any key can be a modifier key.
http://dmauro.github.io/Keypress/
Apache License 2.0
3.18k stars 313 forks source link

"meta + S" called twice when `is_sequence` was set true #9

Closed tiye closed 11 years ago

tiye commented 11 years ago

Keydown events are always called twice on my demo. I found that if I didn't set is_sequence, things go right, but both meta s and s meta would callback. So here's my code (with keypress.js compiled with coffee 1.6.2):

my_combos = [
  {
    "keys"      : "meta s"
    "is_exclusive"  : true
    "is_sequence"   : true
    "on_keydown"  : ->
      console.log("You pressed shift and s together.")
      event.preventDefault()
    "this"      : @
  }
]
keypress.register_many(my_combos)

In the _key_down function, _fire was triggered twice, first time at: https://github.com/dmauro/Keypress/blob/master/keypress.coffee#L314 second time at: https://github.com/dmauro/Keypress/blob/master/keypress.coffee#L335 I haven't figured out how it happens so far.

dmauro commented 11 years ago

is_sequence is for sequential combos, for instance, that would fire when you press meta followed by s. It sounds like what you want is is_ordered to be set to true, which means that you have to press the keys down in the ordered specified (meta + s would work, s + meta would not).

tiye commented 11 years ago

My mistake. Now it's right after setting to is_ordered: true.