I need a program, say a Python script, to be notified when the CapsLock and NumLock status are changed.

I may have several keyboards and the code must run in user space so I can't rely on a kind of keylogger to receive KEY_CAPSLOCK events.

Some tools fire visual notifications by running xset q in a loop, but I can't find anything useful for receiving direct events. I don't want to use the xset method because I don't want to use a loop, I don't want to use an external tool and also that would need an X server.

  • To the person who put a -1: feel free to explain so that I can try to fix the problem
    – PeterHerb
    Jun 21, 2020 at 11:32
  • I've just added my -1 too, because it is mainly not clear what you want, although I feel the question you want to ask is useful. What do you mean with "to be notified"? It's too vague. And, if it turns out to be simpler, why not running xset q in a loop? Please fix those issues and I will be glad to retract my downvote.
    – Quasímodo
    Jun 21, 2020 at 11:46
  • Thanks for the info, I tried to better explain what I'm looking for, not sure it's clearer
    – PeterHerb
    Jun 21, 2020 at 12:10
  • Thanks for your effort, I think it is clear now and the question is interesting and useful. But bear in mind you mention Python and then that you do not want an external tool. If the latter is true, you would also blacklist Python and go for a shell script.
    – Quasímodo
    Jun 21, 2020 at 12:18
  • 1
    Keyboard events including CapsLock status are available as X events or kernel input layer events, which one do you want? That also depends on what you want to do with this information, and what the rest of the program is supposed to do. Please edit question with this information. If you are not running an X server in the first place, please also include this information.
    – dirkt
    Jun 21, 2020 at 13:43


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.