kernc / logkeys

:memo: :keyboard: A GNU/Linux keylogger that works!
Other
758 stars 253 forks source link

Can't get Capslock state on wayland #229

Open Yatogaii opened 3 years ago

Yatogaii commented 3 years ago

This statement is only applicable to OS using xorg, and cannot get the value of capslock correctly in Wayland key_state.capslock_in_effect = execute(COMMAND_STR_CAPSLOCK_STATE).size() >= 2; I'm curious how to get the capslock value in Wayland

kernc commented 3 years ago

Does setleds work, as pointed out in this SO thread?

kernc commented 3 years ago

We already use setleds in case xset fails: https://github.com/kernc/logkeys/blob/2539ccb89e20a3fbdeaa186f62e54719602a7143/src/logkeys.cc#L52 Do you have it installed (part of kbd package).

kernc commented 3 years ago

Reading /sys/class/leds/inputX::capslock/brightness is another option ...

Yatogaii commented 3 years ago

#define COMMAND_STR_CAPSLOCK_STATE ("{ { xset q 2>/dev/null | grep -q -E 'Caps Lock: +on'; } || { setleds 2>/dev/null | grep -q 'CapsLock on'; }; } && echo on") It can get correct result on Xorg but the result is always 0 when it work on wayland. I have tried setleds -D +caps command ,it can work at both Xorg and wayland , but it only works well on VT(i mean Ctrl+Alt+F2orF3 that window), it don't work on GUI. I also tried using ioctl(fd,KBGETLED,&res);,but it always get 0. Is it because of my virtual machine problem? My OS is ubuntu16.04 using Xorg and ubuntu21.04 usging wayland.

Yatogaii commented 3 years ago

I tried ioctl(fd,KDETLED,0x04) and it works well on GUI However, regardless of the value of capslock, the return value of kdgetled is always 0. However, after kdset led, 0x04, no matter how you press the capslock key, the value of kdgetled will become 0x04 instead the true value of capslock state It seems that the value of kdgetled is only 0 or the value modified by kdsetled, regardless of the state of the key itself Any ideas?