Know and change caps lock status under wayland


I got this script for nvim:

" Turn off CapsLock when returning in normal mode
function TurnOffCaps()  
    let capsState = 
    matchstr(system('xset -q'), '00: Caps Lock:\s\+\zs\(on\|off\)\ze'")
    if capsState == 'on'
        silent! execute ':!xdotool key Caps_Lock'

autocmd InsertLeave * call TurnOffCaps()

The solution is smart, but there is no xset and xdotool for Wayland.
Is there anothe way to get and switch the caps lock status ?

Hello @Weg :wink:

Well just an idea…

  1. Instead of xset -q you could use:
cat /sys/class/leds/input*::capslock/brightness 

0 → off
1 → on

It works also even without led on your keyboard :smiley:

  1. Instead of xdotool, use ydotool. :wink:
1 Like

Thanks. The first one works like a charm.

The second… I have to configure nvim to launch the deamon each time it start. I made a try in the terminal. I was able to turn on caps lock, but not to turning it off. It looks like something I will need an afternoon again to configure…