Is there any way, in Python, to "programmatically" (:-) change the CAPS LOCK/NUM LOCK/SCROLL LOCK states. This isn't really a joke question - more like a real question for a joke program. I intend to use it for making the lights do funny things ;-)
+10
A:
If you're using windows you can use SendKeys for this I believe.
http://www.rutherfurd.net/python/sendkeys/
import SendKeys
SendKeys.SendKeys("""
{CAPSLOCK}
{SCROLLOCK}
{NUMLOCK}
""")
sparks
2009-05-12 19:28:17
It does have internal code designed to toggle Numlock, if nothing else.
Brian
2009-05-12 19:32:35
Thanks. I didn't know Python had SendKeys.
Lucas Jones
2009-05-13 15:21:19
+6
A:
On Linux here's a Python program to blink all the keyboard LEDs on and off:
import fcntl
import os
import time
KDSETLED = 0x4B32
SCR_LED = 0x01
NUM_LED = 0x02
CAP_LED = 0x04
console_fd = os.open('/dev/console', os.O_NOCTTY)
all_on = SCR_LED | NUM_LED | CAP_LED
all_off = 0
while 1:
fcntl.ioctl(console_fd, KDSETLED, all_on)
time.sleep(1)
fcntl.ioctl(console_fd, KDSETLED, all_off)
time.sleep(1)
Benji York
2009-05-13 16:32:23
I'm on Linux right now so I'll give that a shot. I was aiming for Windows though - should have made that clear :)
Lucas Jones
2009-05-13 17:40:23
Nice, but it needs root privs to open /dev/console (unless permissions are set). Any way for it to run as a normal user?
Lucas Jones
2009-05-13 17:43:42