Conversation
There was a problem hiding this comment.
This is in cross-platform code, so we can't pull in a Windows library.
One option would be to requery key state when the control is focused and then have the control update the key state itself. That would presumably be fine everywhere. Another option would be to have this class take an interface which can call whichever platform-specific code is necessary to check key state.
There was a problem hiding this comment.
That's fair. I reverted the changes to seek a new solution.
I saw WinUIPlotExtensions has a UpdateKeyStateFromModifiers method that looks at the framework's keyboard state system and updates the KeyState to match which modifiers the framework says are pressed. I used the same pattern for WpfUIPlotExtensions (and used Claude for the other frameworks I'm less familiar with).
The result should be that this now works with all of the supported frameworks and is crossPlatform on the frameworks that support it. Tested only with WPF on Windows. Both of my bullet points in initial comment pass.

The KeyboardState class only receives key information if the application has focus. This causes some issues with modifier keys.
Refactoring the keyboard system entirely may be the best option, but i didn't want to dive that deeply. Instead, i just put in a low-risk workaround specific to modifier keys.
if .net standard is ever dropped then we could remove the pinvoke and simply go with System.Windows.Input's Keyboard.Modifiers.HasFlag