29 January 2011

genmon-numlock.py

One of the problems with wireless keyboards is they have no indicator lights for num lock, caps lock, etc. If you are running Gnome you can use lock-keys-applet, but Xfce currently has no native panel plugin for displaying the lock keys.

Fortunately, Xfce does include a generic monitor panel plugin, which you can use for almost anything.
#!/usr/bin/python

indicator="Num Lock"
text = ""
on_icon = "/usr/share/pixmaps/pidgin/status/16/available.png"
off_icon = "/usr/share/pixmaps/pidgin/status/16/invisible.png"

from ctypes import *

def GetIndicatorState(name):
    state = c_bool(False)

    libX11 = CDLL("libX11.so")
    display = libX11.XOpenDisplay(0)
    atom = libX11.XInternAtom(display, name, c_bool(False))
    libX11.XkbGetNamedIndicator(display, atom, 0, byref(state), 0, 0)
    libX11.XCloseDisplay(display)
        
    return state.value

if GetIndicatorState(indicator):
    print("" + on_icon + "")
else:
    print("" + off_icon + "")
Adjust the four variables at the top to your taste, and set genmon to run it every second. The updates aren't instantaneous, and it's a little resource heavy, but it's better than nothing.

1 comment:

alertlock said...

I really understand the importance of when Should we Call a Locksmith. You can contact San Antonio Locksmith San Antonio TX for professional services. You can opt for professional San Antonio Locksmith San Antonio TX and other information.