3 ms·
> But key events should be on key-down Why? I like how keyup is less ambiguous: it avoids the question “what do I do if the user is holding the key down?” I
by Waterluvian 6y ago
> But key events should be on key-down
Why?
I like how keyup is less ambiguous: it avoids the question “what do I do if the user is holding the key down?”
I also like being able to hold the key down to cue up a command and then at the right time, pull my hand away to execute crisply. For video editing mainly.
I’m not saying keyup is the only answer. Just that there isn’t one obvious answer.
- jackewiehose 6y ago> Why? Because of the reported bug in this example (which I also encountered quite often): - user hits ESCAPE - my window gets key-down/ESCAPE and closes itself - your window (which happens to be the next in the focus-order) gets key-up/ESCAPE and closes itself > I also like being able to hold the key down to cue up a command and then at the right time, pull my hand away to execute crisply Ok, but if your window wants to support this behavior (which is not very common) you have to watch for key-up AND key-down like the bug-report suggests.
- cortesoft 6y agoWhat if the OS only sent key-up events to a window if it also received the corresponding key-down event?
- jackewiehose 6y agoThen we wouldn't have this conversation.
- dmurray 6y agoThen you'd lose useful functionality like dragging a file from your file manager to an application window to open it there.
- efreak 6y agoThat's your mouse button, not a keyboard key. Although modifier keys occasionally are used, what's important here is the state of those keys (ctrl for copy, shift/alt or whatever for shortcut); nothing happens when you release them.
- dmurray 6y agoYou can do it with arrow keys, too. I remember doing this all the time back on Windows 3.1 and I'm sure it's still used now especially by people with disabilities. Anyway, there's a way to fix this: send a reference to the key-down event when you send the key-up event. Then the receiving window can determine if it cares about it or not. If this is a security hole, send a reference to the window where the key-up event was sent instead.
- deleted 6y ago[deleted]
- dkersten 6y agoKeydowns have the physical button analogue: when you press a physical button, it immediately closes the contact, it doesn't wait until you lift your finger again. Not saying key down is better than key up, there are certainly arguments for both.
- fiddlerwoaroof 6y agoCan’t physical buttons work either way, depending whether you want to break a normally closed circuit or close a normally open circuit.
- mantap 6y agoImagine a physical button on a car stereo. It activates when you press it, not when you press and release it.
- JdeBP 6y agoYour experience of physical buttons is limited. There are many sorts. To pick an apposite example: The "Pause" button on old tape players used to be press-and-release to change state. Because it was a direct mechanical linkage and not motorized on some players/recorders, this made it possible to perform quite accurate editing with very basic kit: pressing and releasing pause to pause, pressing it again and keeping it held down, and releasing exactly when one desires to un-pause.
- phab 6y agoNow THERE's a rabbit-hole if ever I saw one. Here's an 8-part (!) article [0] on why a physical button is in reality... nowhere near that simple. [0]: https://www.eejournal.com/article/ultimate-guide-to-switch-debounce-part-1/ https://www.eejournal.com/article/ultimate-guide-to-switch-d...