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

ALT CTRL 1 works, but ALT 1 and CTRL 1 do not. #149

Open EdwardGioja opened 5 years ago

EdwardGioja commented 5 years ago

This is just one example. I'm having the issue with a number of keys, like other numbers and "K".

I am NOT using the number keypad.

I am using prevent_repeat, is_unordered, is_exclusive, is_solitary, and the "on_keydown" function. is_exclusive is strange... for instance, on CTRL1, if I use prevent_default, I get nothing. If I don't use prevent_default, it changes to the first tab (the default use of CTRL1).

The debugger shows that they are registered: image

EdwardGioja commented 5 years ago

I just figured out the issue. If I have a CTRL1 and an ALT1, both work. I can not, however, have an ALT+CTRL+1 and an ALT+1 or a CTRL+1.

I can work around this, although it does cut down on the number of "hot keys" my users can create. It is something you may want to look at.

BTW, this is behavior in the last version of Firefox and Edge

dmauro commented 5 years ago

It's hard to say without seeing the other combos, but it sounds like you're probably bumping into this specific detail of is_solitary:

When we set is_exclusive to true, we will not call the callbacks for any combos that are also exclusive and less specific.

So in your follow-up combo, for instance. If you have Alt+Ctrl+1 and Alt+1 and they're solitary, Alt+1 could never fire because it would always be trying to fire Alt+Ctrl+1. Does that answer your question?

EdwardGioja commented 5 years ago

That makes sense, and it explains the rest of the behavior. In case you haven't seen my subsequent entries, I found I can use ALT+CTRL+1 OR I can use BOTH ALT+1 and CTRL+1, but not all three.

So, there isn't any way to use all three combos, and is_solitary? For the most part, my users use these hotkeys to insert text. SO if one assigned ALT+1 to insert "hello world" and ALT+CTRL+1 to insert the words "goodbye cruel world", I would not want a combination of the two...so I have to use is-solitary. I can see, however, that is-solitary would reject the alt+1 definition IF atl+ctrl+1 is defined.

Unfortunately, this does affect one of my users who has defined all of the number keys to have all three types of shortcuts. This worked fine until Firefox Version 65 stopped supporting the system's keypress event for non-printable characters.

A little nonsense now and then is relished by the wisest men. - Roald Dahl

Edward Gioja Software Development Manager 779-772-8349

From: David Mauro notifications@github.com To: dmauro/Keypress Keypress@noreply.github.com Cc: EdwardGioja Edward_Gioja@ilnb.uscourts.gov, Author author@noreply.github.com Date: 04/21/2019 09:05 AM Subject: Re: [dmauro/Keypress] ALT CTRL 1 works, but ALT 1 and CTRL 1 do not. (#149)

It's hard to say without seeing the other combos, but it sounds like you're probably bumping into this specific detail of is_solitary: When we set is_exclusive to true, we will not call the callbacks for any combos that are also exclusive and less specific.

So in your follow-up combo, for instance. If you have Alt+Ctrl+1 and Alt+1 and they're solitary, Alt+1 could never fire because it would always be trying to fire Alt+Ctrl+1. Does that answer your question? ? You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

dmauro commented 5 years ago

Yeah, the crux of the problem is, with the way the system is built, when the player presses ALT+1, we're then either a) waiting for CTRL to also be pressed to fire the more complex match, or b) fire ALT+1 and then risk firing both if they then pressed CTRL.

This could be avoided if we then invalidated those keys that matched the ALT+1, but it would still be a bit of a user problem because then you'd have to make sure to hit CTRL first if you wanted to do ALT+1+CTRL so that you didn't accidentally trigger ALT+1. Another route you could go is to do some sort of timing where we match the combo after a set amount of ms with no other inputs, which might just be the best option, at least for what you're looking for, but when I first designed this, I was trying to avoid timing stuff (except for the sequences) because it didn't make sense for my use case.

tl;dr It's kind of a design problem that hits the boundaries of how I designed this system to work. FWIW there are a lot of other key-command JS solutions out there and I'd be willing to bet there's one that works better for your use case. Good luck!

EdwardGioja commented 5 years ago

I thank you for the reply and the explanation. After reviewing current usage, I have decided to limit users to ctrl OR alt. Your product works great with this.

Edward Gioja Software Development Manager (779)772-8349

On Apr 28, 2019, at 10:10 AM, David Mauro notifications@github.com wrote:

Yeah, the crux of the problem is, with the way the system is built, when the player presses ALT+1, we're then either a) waiting for CTRL to also be pressed to fire the more complex match, or b) fire ALT+1 and then risk firing both if they then pressed CTRL.

This could be avoided if we then invalidated those keys that matched the ALT+1, but it would still be a bit of a user problem because then you'd have to make sure to hit CTRL first if you wanted to do ALT+1+CTRL so that you didn't accidentally trigger ALT+1. Another route you could go is to do some sort of timing where we match the combo after a set amount of ms with no other inputs, which might just be the best option, at least for what you're looking for, but when I first designed this, I was trying to avoid timing stuff (except for the sequences) because it didn't make sense for my use case.

tl;dr It's kind of a design problem that hits the boundaries of how I designed this system to work. FWIW there are a lot of other key-command JS solutions out there and I'd be willing to bet there's one that works better for your use case. Good luck!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.