winit icon indicating copy to clipboard operation
winit copied to clipboard

get NumLock status

Open jice-nospam opened this issue 5 years ago • 5 comments

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 ?

jice-nospam avatar Jan 31 '20 09:01 jice-nospam

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

jice-nospam avatar Feb 01 '20 19:02 jice-nospam

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

ArturKovacs avatar Jan 02 '21 12:01 ArturKovacs

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 avatar Dec 19 '23 14:12 Plecra

@Plecra fill free to extend the event if they are reliably observable on platforms.

kchibisov avatar Dec 19 '23 14:12 kchibisov

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

danielhjacobs avatar May 16 '24 13:05 danielhjacobs