I saw several answers suggesting using Keyboard.Modifiers to determine if the KeyDown for a key that had a set of modifiers. Unfortunately, since Keyboard.Modifiers returns the current state of modifiers (instead of the modifier state when a key is pressed), this leads to a really annoying intermittent error for fast typists.
In particular, imagine that someone presses Ctrl + A and releases Ctrl only a few milliseconds after pressing A. Now imagine that the system is under heavy load; the key handler started to execute, but was unloaded for 50 ms. By the time the key handler is executed again, the current state of Ctrl is "released". The key handler will now think that "A" was pressed without Ctrl, and this is bad.
Similarly, if a fast typist got into A, Ctrl + End and my application uses Keyboard.Modifiers , instead, one would observe Ctrl + A ...
In WinForms, the KeyDown tells me the Ctrl state, even if it is already fired by the time the event is processed. How can I get the same behavior in WPF?
Edit : it is possible that Keyboard.Modifiers does not actually retrieve the βcurrentβ modifier keys, but instead the modifier keys relate to the current message being processed. In WinAPI, this was the difference between the async and non-async key functions. Unfortunately, the documentation does not mention what exactly means "current." If anyone knows, say so.
Roman starkov
source share