Karabiner-Elements icon indicating copy to clipboard operation
Karabiner-Elements copied to clipboard

Controlling the Num Lock and Scroll Lock lights for our own nefarious purposes

Open Muirium opened this issue 2 years ago • 8 comments

I know the Mac has no Num Lock or Scroll Lock modes. But I would like to be able to control those two LEDs on PC keyboards from Karabiner, for my own purposes.

For example: the Topre Realforce 87u.

This tenkeyless keyboard has an integrated numpad (like the IBM SSK and indeed my PowerBook) with U I O becoming 4 5 6 etc. when Num Lock is engaged. You can see the front legends on the image above. This works great in Windows, where the LED inside the Num Lock key will shine when engaged. Sadly, you get neither on the Mac: no numbers and no light. Well, I'd like to fix this.

Besides, Apple did exactly the same on the aluminium PowerBooks:

I can, and do, make my own numpad layer in Karabiner. But it would be much nicer to have the LED on the keyboard light up when this mode of mine is engaged. I'd just love to be able to send it commands for myself. And why not the Scroll Lock light as well, on all those fullsize keyboards which have all three?

Another trick I play with numpads is using them for mouse control. I have rules to convert my fullsize keyboards' numpads into a virtual mouse, with diagonals and wheel scrolling all setup on those many keys. I toggle it on and off with the Num Lock key. But again I'd really like a light on the keyboard (which always has one already!) to warn me which mode I'm in.

So how about it? Can we get commands to turn on and off the Num Lock and Scroll Lock lights in Karabiner? I'd use them to show me layer state, like I just mentioned. But the opportunities are wide indeed.

Muirium avatar Aug 16 '22 16:08 Muirium

If this is simply impossible for Karabiner to ever achieve, do say so. The Caps Lock LED sync between all attached keyboards has got my hopes up. But is that mechanism even able to address lock lights the Mac itself does not use?

Muirium avatar Aug 16 '22 16:08 Muirium

It is possible to set keyboard LEDs; there is a usage page for LEDS. However, I don't whether that will toggle keyboards' internal modes. You can test it using below programs. Note that you will have to either turn off input modification for that device, or quit KE, for this to work.

  • https://github.com/damieng/setledsmac
  • https://github.com/akiym/Mac-Keyboard-LED

Edit: I haven't used those myself. I have checked the code, and it seems okay, but use at your own risk. Also, it's not sure whether these will work with recent macOS versions.

MuhammedZakir avatar Aug 17 '22 03:08 MuhammedZakir

Thanks for the lead, Muhammed!

I built setledsmac on my M1 Air, where it works quite nicely for Num Lock and Scroll Lock LED control on external keyboards when Karabiner isn’t running. So it’s possible to control them on the Mac after all! When Karabiner is active, setledsmac doesn’t work, just like you said.

This comment suggests scripting Karabiner’s device list when doing LED state changes. Do you know if there’s a more Karabiner-style way to do this inside a complex rule (running a shell script if necessary) rather than hacking karabiner.json externally while live? Can Karabiner’s active devices be manipulated from within a complex rule? Because momentarily switching it off, updating the LEDs, then turning it back on again could be just the trick I need.

https://github.com/damieng/setledsmac/issues/17

Muirium avatar Aug 17 '22 20:08 Muirium

Hooking up several keyboards, like a crazy person, I can report how this almost works. The lock light behaviour is a little different on different keyboards. Nothing I couldn't resolve with my own device_if complex rules in Karabiner, however. If only I could access them with it running…

Filco Majestouch 2 Tenkeyless: This USB native, non-programmable keyboard has Caps Lock and Scroll Lock lights, but no Num Lock. setledmac will manipulate "all 3", reporting no error when accessing the Num Lock which is not there. The keyboard behaves normally besides its lights. Entering Caps Lock does not GO ALL CAPS.

Topre Realforce 87u: This USB native, non-programmable tenkeyless keyboard has Caps Lock and Num Lock LEDs, integrated into their respective keys. setledmac will toggle the Caps Lock light with no effect on typing. But toggling the Num Lock light d6es 5n fact engage the 5ntegrated n40pad 06de! Turn the Num Lock light back off and the alpha keys are restored, so this keyboard does in fact internally produce numeric mode. EventViewer shows the keys as keypad_1 etc., matching all the front legends. Including even the comma key which becomes 00 by pressing 0 twice.

NMB RT8255C+: This fullsize vintage PC/AT keyboard has an internal TMK AT to USB programmable converter, and all 3 lock lights in hardware, above the numpad. setledmac freely manipulates all of them, and the keyboard simply sends the same keystrokes no matter their state. I believe this is how it's meant to be for all keyboards, without size-reducing sneaky tricks like Topre's above!

Muirium avatar Aug 17 '22 22:08 Muirium

I neglected to mention: Karabiner is kind enough to leave the Num and Scroll Lock LEDs maintain their state when it is reactivated on each altered keyboard. The tenkeyless Realforce stays in numpad mode as it should.

The only problem remains Karabiner blocking access while it is active for any given keyboard.

Muirium avatar Aug 18 '22 08:08 Muirium

I’d be very happy if Karabiner either:

  1. Allowed setting the Num Lock and Scroll Lock LEDs in complex rules. Let us look after implementing them! I just want to control the light.
  2. Allowed setleds to control those two lights, as I could run it by a shell command. Currently, Karabiner blocks it out.

I’m very pleased with my numpad mouse layer / numeric toggle and just wish I could shine the Num Lock LED right there on the vintage keyboard hardware to tell me which mode is active.

Muirium avatar Aug 20 '22 08:08 Muirium