Skip to content

Conversation

@yuxqiu
Copy link
Contributor

@yuxqiu yuxqiu commented Dec 6, 2025

The current Caps Lock detection does not work correctly on my Sofle keyboard: the state instantly flips from true back to false.

After checking the logs, the cause is clear:

if event.Type == evKeyType && event.Code == keyCapslockKey && event.Value == keyStateOn {
    time.Sleep(50 * time.Millisecond)
    m.readAndUpdateCapsLockState(deviceIndex) // triggered here
} else if event.Type == evLedType && event.Code == ledCapslockKey {
    capsLockState := event.Value == keyStateOn
    m.updateCapsLockStateDirect(capsLockState)
}

and inside the called function:

ledStates, err := device.State(evLedType)
...
capsLockState := ledStates[ledCapslockKey] // root cause

My keyboard has no physical Caps Lock LED, so device.State(EV_LED) returns an empty map.
Accessing it yields false, which forces the state back to off every time.

This PR adds a simple check: if ledStates is completely empty, we skip the update entirely instead of treating Caps Lock as off.

The change has minimal impact on other devices:

  • When ledStates is non-empty (normal case), behaviour is unchanged.
  • When it is empty, we now avoid the incorrect forced-off state that some keyboards currently suffer from.

Actually, I wonder if it is even necessary to have the branch below since it seems EV_LED event will always be issued by the kernel?

if event.Type == evKeyType && event.Code == keyCapslockKey && event.Value == keyStateOn {
    time.Sleep(50 * time.Millisecond)
    m.readAndUpdateCapsLockState(deviceIndex) // triggered here
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant