winit
winit copied to clipboard
get NumLock status
Right now, we can detect key press on the numlock key, but is there a way to check the status (on/off) of the numlock ?
In fact this might be a bug because we get both ArrowLeft KeyboardInput event and '4' ReceivedCharacter event when we press the numpad 4 key whereas it should be one or another depending on the numlock status
The original description and the comment following it describe distinct issues.
The first one will require the addition of a new API which can query the status of the numlock key. This overlaps with #1010
The second one is going to be resolved by #753
I'd like to expand this feature request to resolve https://github.com/khonsulabs/gooey/issues/81. The ModifiersState
that we can receive in ModifiersChanged
doesn't allow us to read the NumLock or CapsLock states. This doesn't overlap with issue 1010 as an event-based API is still useful even before we have an api to mirror getkey
, and it wasn't resolved by #753, though I'm not sure why.
Each KeyboardEvent implementation tracks numlock and capslock. Here's where they're read in linux:
https://github.com/rust-windowing/winit/blob/cc33212479b5c9e75ff6ceb16f7a817ddf9950f2/src/platform_impl/linux/common/xkb_state.rs#L649-L651
(and here in windows)
but those aren't forwarded to the public ModifiersState
https://github.com/rust-windowing/winit/blob/cc33212479b5c9e75ff6ceb16f7a817ddf9950f2/src/platform_impl/linux/common/xkb_state.rs#L657
@Plecra fill free to extend the event if they are reliably observable on platforms.
Also wondering the same for Caps Lock and Scroll Lock. It would add a way to fix https://github.com/ruffle-rs/ruffle/pull/13513#issuecomment-1774270434
The JavaScript way to do this is with https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState / https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/getModifierState