damieng / setledsmac

Set your keyboard LEDs from the Mac OS X command-line
GNU General Public License v2.0
142 stars 35 forks source link

Can't use with karabiner-Element 11.4.0 #7

Closed fz68 closed 6 years ago

fz68 commented 6 years ago

Mac Book Pro 2012 later with High Sierra 10.13.1

sudo setleds -v result:

    SetLEDs version 0.2 - http://github.com/damieng/setledsmac

     "Apple Internal Keyboard / Trackpad" ?num ?caps ?scroll

    Some state could not be determined. Please try running as root/sudo.`
damieng commented 6 years ago

This would appear to be an issue with Karabiner. They are interfering with the built in keyboard device but implementing an incomplete API that subsequently prevents getting the keyboard state using the IOKit apis.

Specifically this api call https://github.com/damieng/setledsmac/blob/master/Source/SetLEDs/main.c#L116 always returns zero when attempting to obtain the pointer to the integer LED value.

I did notice that their driver at https://github.com/tekezo/Karabiner-Elements/blob/f3ddb6ec45e6ded9d9ed05b968bc70990b91f06f/src/vendor/Karabiner-VirtualHIDDevice/src/VirtualHIDKeyboard/VirtualHIDKeyboard.cpp does not support the kHIDPage_LEDs usage page which would explain why we can't get the keyboard state from that although I'm not sure what they're doing that interferes with the internal Apple keyboard (replacing the driver or hooking it?)

rodolfo-gonzalez commented 6 years ago

There is a way to use setleds and Karabiner-Elements, basically is to close Karabiner-Elements set leds ON with setleds and then open Karabiner-Elements it worked for me disabling Manipulate LED under Devices in Karabiner-Elements

here is a small fish function i wrote:

function masterkeys-pro-led
    set setleds_cmd "$HOME/.dotfiles/setleds"
    set karabiner "Karabiner-Elements"
    set masterkeys "MASTERKEYS PRO S"

    if eval $setleds_cmd -v | grep "$masterkeys" > /dev/null
        if pgrep -i "karabiner"
            sudo kill (pgrep -i "karabiner")
        end
        eval $setleds_cmd -v -name '$masterkeys' +scroll +caps
        open -a $karabiner
    end
end
manolodeinternet commented 6 years ago

Hi @rodolfo-gonzalez , what a great solution !!!

I'm newby at keyboard programing. Would you be so kind of sharing with us how do you implement the 'function master keys-pro-led' ? Because I can't tell if that code must be compiled through Xcode or a batch terminal file. Can you give us a short description of the process or a tip, please ?

Thanks in advance for taking the time to read my question. Regards !!!

NOTE: (Using your code will be great for me, because I'm spending weeks looking though Internet for a solution for controlling LEDs lights on my old IBM M '89 with my Mac. I'm trying right now with ControllerMate, but I found the same problem. Karabiner VirtualHIDKeyboard interferes with ControllerMate too.)

rodolfo-gonzalez commented 6 years ago

@xcode-manolo that is a small fish function you will have to either use https://fishshell.com/ or translate that function to a bash script.

What the function does is:

this is the only way i could make the work, is very important that you close karabiner elements before using setleds once you have turned on all leds, you can use karabiner as normal

cheers.