Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anybody know how to toggle caps lock on/off in Python?

I'm trying to toggle caps lock on/off when the two shift buttons are held down for a second. I've tried using the virtkey module, but it's not working. That module does work for other keys though, so I don't think I'm using the module incorrectly.

Does anybody have a way for doing this?

Just to be clear, I want to actually toggle caps lock on/off and not just the LED.

Thanks!

like image 614
Justin Avatar asked Oct 31 '25 01:10

Justin


1 Answers

This works for me (turns the led on and off as well as enable/disable caps)

import virtkey

v = virtkey.virtkey()
v.press_keycode(66)
v.release_keycode(66)  # first release doesn't release it
v.release_keycode(66)

Here are some more examples

v.press_keycode(66)    # turns capslock on
v.release_keycode(66)
v.press_keycode(66)    # turns capslock off
v.release_keycode(66)

You can also get a toggle like behaviour just using release_keycode

v.release_keycode(66)  # toggles capslock
v.release_keycode(66)  # toggles back again capslock
like image 138
John La Rooy Avatar answered Nov 02 '25 15:11

John La Rooy