News for hackers. Stuff that matters.
Re:Comments by a developer inside the Windows Media Player s... by jackewiehose on Saturday September 26, 2020 @07:25PM (#24602943)
The bug here is in media player to listen on key-up events. Mouse-button-up makes sense because the user can move the mouse to cancel the click. But key events should be on key-down and that's how it is done most of the time. So if you use key-up you run into these problems.
Re:Comments by a developer inside the Windows Media Player s... by Waterluvian on Saturday September 26, 2020 @07:40PM (#24603036)
> 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.

Re:Comments by a developer inside the Windows Media Player s... by jackewiehose on Saturday September 26, 2020 @07:56PM (#24603107)
> 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.

Re:Comments by a developer inside the Windows Media Player s... by cortesoft on Saturday September 26, 2020 @08:05PM (#24603147)
What if the OS only sent key-up events to a window if it also received the corresponding key-down event?
Re:Comments by a developer inside the Windows Media Player s... by dmurray on Saturday September 26, 2020 @08:37PM (#24603290)
Then you'd lose useful functionality like dragging a file from your file manager to an application window to open it there.
Re:Comments by a developer inside the Windows Media Player s... by efreak on Saturday September 26, 2020 @10:12PM (#24603654)
That'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.
Re:Comments by a developer inside the Windows Media Player s... by dmurray on Sunday September 27, 2020 @06:02AM (#24605534)
You 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.

Re:Comments by a developer inside the Windows Media Player s... by jackewiehose on Saturday September 26, 2020 @08:14PM (#24603188)
Then we wouldn't have this conversation.
Re:Comments by a developer inside the Windows Media Player s... by dkersten on Saturday September 26, 2020 @11:31PM (#24604023)
Keydowns 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.

Re:Comments by a developer inside the Windows Media Player s... by JdeBP on Sunday September 27, 2020 @05:20AM (#24605334)
Your 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.
Re:Comments by a developer inside the Windows Media Player s... by phab on Sunday September 27, 2020 @11:30AM (#24607367)
Now 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-d...

Re:Comments by a developer inside the Windows Media Player s... by fiddlerwoaroof on Sunday September 27, 2020 @01:12AM (#24604383)
Can’t physical buttons work either way, depending whether you want to break a normally closed circuit or close a normally open circuit.
Re:Comments by a developer inside the Windows Media Player s... by mantap on Sunday September 27, 2020 @01:33AM (#24604449)
Imagine a physical button on a car stereo. It activates when you press it, not when you press and release it.
Re:Comments by a developer inside the Windows Media Player s... by Someone on Sunday September 27, 2020 @01:53AM (#24604517)
“But key events should be on key-down”

Should they, in general? If you want to press a key combination, you never press the two keys at exactly the same time. So, if key events were on key-down, you would have to press modifiers before letters to type capital letters, use keyboard shortcuts, etc. I think that would be annoying and slow typists down.

It also rules out using bare modifier key presses as input methods, but that is less of an impact.

Re:Comments by a developer inside the Windows Media Player s... by williamdclt on Sunday September 27, 2020 @06:51AM (#24605711)
I've never seen a system where you can press modifiers _after_ letters, what are you using? Letters are definitely inserted on key down on all windows/linux/macos I've used
Re:Comments by a developer inside the Windows Media Player s... by fooker on Sunday September 27, 2020 @01:36PM (#24608432)
Ligatures pretty much work this way.
Re:Comments by a developer inside the Windows Media Player s... by jml7c5 on Sunday September 27, 2020 @02:12AM (#24604598)
I would argue keydown is generally right, for the sake of latency and immediacy of action.

Do people who want a capital 'A' ever intentionally type A-Shift instead of Shift-A? I've never heard of it before.

Re:Comments by a developer inside the Windows Media Player s... by JdeBP on Sunday September 27, 2020 @05:22AM (#24605348)
Where on Earth have you been typing capital letters? One does have to press the modifier first on conventional home and personal computer keyboards.
Re:Comments by a developer inside the Windows Media Player s... by InfiniteRand on Monday September 28, 2020 @04:01PM (#24620685)
There is the case of a sustained key press, where holding down the key might be part of navigation and only on key-up is the navigation finished, is it possible on platforms like Windows to distinguish between the sustained key up vs a normal key up?