Skip to content

Feature: indicator led selection - #4

Open
dmig wants to merge 5 commits into
holgertkey:mainfrom
dmig:feature/led-selection
Open

dmig wants to merge 5 commits into
holgertkey:mainfrom
dmig:feature/led-selection

Conversation

@dmig

@dmig dmig commented Oct 22, 2026 •

Copy link
Copy Markdown

This closes #2.

-led option allows to choose LEDs for indication: scroll, num, caps
No indication by default, multiple LEDs are possible.

Had to change approach of LED toggling to avoid unwanted keyboard behavior.
Please squash on merge.

dmitry-gils and others added 5 commits October 22, 2026 09:54
Add -led CLI option accepting scroll, num, caps values (comma-separated).
Multiple LEDs can be active simultaneously. Default remains scroll lock
to preserve backward compatibility.

Changes:
- layout_indicator: replace set_scroll_lock_state with generic
  set_indicator_leds that iterates an ACTIVE_LEDS bitmask
- cli: extract_led_option parses -led from args, background_command_line
  preserves the setting when re-launching
- main: apply LED mask before starting indicator
- console_log, interactive_menu: generalize LED label text

Closes holgertkey#2
Change ACTIVE_LEDS default from LED_SCROLL to 0, so no indicator
is used unless the user explicitly passes -led. This allows a
'no LEDs' configuration that was not possible before.
Without the marker, set_key_toggle(VK_CAPITAL) sends a CapsLock
press that the keyboard hook sees as an external injection, blocks
it, and triggers an unwanted layout switch — causing -led caps to
immediately revert after every switch.
Replace SendInput-based LED toggling with IOCTL_KEYBOARD_SET_INDICATORS
which talks directly to the keyboard class driver. This decouples the
physical LED from the OS toggle state, fixing the CapsLock LED indicator
issue where toggling the LED also changed the CapsLock typing state.

The IOCTL approach:
- Opens \\Device\\KeyboardClass0 via DefineDosDevice + CreateFile
- Uses DeviceIoControl to set LED flags directly on the hardware
- Does NOT require admin privileges (FILE_ANY_ACCESS)
- Works on USB keyboards (kbdclass -> kbdhid -> HID output report)
- Handle is opened lazily and cached for the process lifetime
- Cleaned up on shutdown (CloseHandle + DefineDosDevice remove)

This applies to ALL LED types (scroll, num, caps), not just CapsLock.
Scroll Lock and Num Lock indicators also no longer affect their
respective toggle states.
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.

Feature request: option to use Caps Lock LED

2 participants