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

Caps Lock remains in the `_keys_down` array. #114

Closed beauwest closed 8 years ago

beauwest commented 8 years ago

I've only tested on a Mac, however, the caps indicator remains in the _keys_down array when turned on. This results in is_solitary key combinations not being able to be triggered since caps is down.

This happens at the OS level, as you can see by triggering Caps Lock on this page: http://www.asquare.net/javascript/tests/KeyCode.html – There is a keyDown event, but no keyUp event until the key is pressed again.

dmauro commented 8 years ago

This seems to be working as expected because it's a toggle button. If you want to do any logic using a lock key, you'll have to get more explicit in the key bindings using down and up events.

beauwest commented 8 years ago

Sorry, I think I'm missing something. The primary issue is with is_solitary: true hotkeys. Since it still sees "caps" as down.

When you say that I'd have to get more explicit to avoid this, what do you mean?

dmauro commented 8 years ago

Do you have a code example of what you're trying to do?

beauwest commented 8 years ago

Sure thing.

Gist: https://gist.github.com/beaudesigns/1ba1750003b36134f680f1fd39a231b1 Do it Live: http://bl.ocks.org/beaudesigns/1ba1750003b36134f680f1fd39a231b1

dmauro commented 8 years ago

Okay, a couple thoughts:

beauwest commented 8 years ago

My current work-around is to register a second combo listener for any is_solitary hotkeys. I use a registration function for our web app so it makes it easy to do, however, it nearly doubles the amount of listeners in the system. I'm sure that has a performance impact. I implemented this work-around until it can be fixed at the library level.

My initial thought would be to implement another option to Keypress, something like normalize_toggle_keys (default to false). When normalize_toggle_keys is true, it would behave like your first option. Basically it would just prevent toggle/locking keys from being added to the _keys_down array. Or have the check for is_solitary ignore those types of keys.

The only reason I'd hesitate to change the behavior entirely, is to not break any existing code out there that implements the current caps behavior. You'd have a better feel for the affects of that though.

I don't think it'd be a good idea to have it persist through refreshes. And I agree that it's scary to have locking keys fire "extra" events.


By the way, sometimes bug reports can come across as harsh when it's a project you've worked hard on. I just wanted to take a moment to say I love Keypress. It's made the web app I'm working on a breeze. Thanks for all your work on it. 👏

dmauro commented 8 years ago

Yeah, I think that's a great idea! I'm open to pull requests, but otherwise I'll try to dig into this when I get the chance (might not be soon 😬 ). And thanks for the encouraging words. I'm really glad to hear this project has been helpful for you 😄

beauwest commented 8 years ago

Pull Request #115