This affects the functionality, too. It is in fact introducing latency by using keyup instead of keydown. Feels bad.
This affects the functionality, too. It is in fact introducing latency by using keyup instead of keydown. Feels bad.
I think you have this wrong, actions generally occur on button release, until that you can move the mouse cursor to a different target, tab to another control, use [ESC] to cancel, and so on. Typing, moving a slider with the cursor keys, and similar things that make use of key repetition while holding down the key are the exception to this.
TAB is otherwise immediate, as is ESC, and the examples of typing, as well. So I'm left wondering, how do they have it wrong?
Because they listed the exceptions to the "act on keyup" rule
Key up is used for when it’s important to only have one occurrence of that event.
Technically you could write code that made key down only react once. But the logical separation makes some sense.
But for reference browsers fire the keypress event on keyup
Basically anything that requires text input from OS-native text input fields to IDEs, word processors, spreadsheets, web browsers, terminal emulators and so on and so forth.
(I confess I’m getting frustrated at the ridiculously large fraction of messages in this thread that have somehow completely misunderstood things.)
In answer to your question: I’ve only really used keyup for either one time events (like keyboard shortcuts for UI elements) and for ending the status of repeated events (eg movement in games, dragging UI elements, etc).
I think if you were to search for key up events in GitHub, most of references might likely be games and other visual interactions rather than text entry.
Edit: I think people are misunderstanding me. I’m asking for an explanation of why, when you have a button focused, pressing Space activates on key up, rather than key down like literally everything else on the keyboard, including Enter on a focused button. (Mouse activates on release.)
These two interactions should behave identically:
- Hover over a button, press mouse button 1, release button 1.
- Tab over to a button, press spacebar, release spacebar.
Why on-screen buttons are UX'd to behave this way is a logical follow-up question. I'd wager that it gives a means to bail out of the clicking (e.g. by moving the mouse out of the on-screen button before releasing mousebutton 1, or by pressing Esc while having spacebar still depressed).
You’re only answering half of the inconsistency: because Enter activates buttons like any other key, on keydown.
So this could be the oddity
Qt: Esc cancels. Tab cancels.
Gtk-4: Spacebar auto-clicks before keyup (probably due to auto-repeat).
Win32: Esc sends Esc to the window. Tab cancels.
Firefox: Esc does nothing. Tab cancels.
So, mileage does vary.
Re. Enter key, that's a different key, so different discussion.
The GTK 4 behaviour feels very much like a bug. I can reproduce it in gtk4-demo and in gtk3-demo. It leads to obviously-nonsensical behaviour, including messed up window focus. I’m tempted to file a bug report, but haven’t had such productive experiences with filing things on GNOME historically as with Firefox or even Chromium.
Why should Enter being a different key be a different discussion? They’re both used to activate buttons, and one is behaving like every single other keyboard interaction, while the other isn’t. (Related: if a link is focused, Enter activates it, Space doesn’t, just doing the normal scroll-down-one-page.)
> if a link is focused, Enter activates it, Space doesn’t
It seems that you answered your own question: different keys, different purposes.
Enter is for "execute the focused action". Spacebar is for "operate the button".