Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change keyboard locks in Python

Tags:

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...

like image 759
Lucas Jones Avatar asked May 12 '09 19:05

Lucas Jones


1 Answers

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) 
like image 155
Benji York Avatar answered Sep 19 '22 18:09

Benji York