This is highly importable, however if you're using XFree (maybe other X servers as well), you could execute xset with the led option. For example, xset led 1 turns on the first LED, whereas xset -led 2 turns off the second.

For XFree be sure to have

Xleds 1 2 3

in your XF86Config or equivalent, otherwise you won't be able to control the LEDs. The X way of doing it is the XChangeKeyboardControl call, available from X11::Protocol as the ChangeKeyBoardControl method of an X11::Protocol instance.

If you run Linux in console mode you might execute setleds. It is implmented using KDGETLEDS and KDSETLEDS ioctl calls for the current terminal. Since ioctl is available under Perl, you can have a look at the appropriate C headers and look at the source code of setleds to figure out exactly what to do.

Regarding Windows, once I've been given the following snippet of VBScript, me being totally incompetent and in need of a quick hack to turn numlock off on a notebook at startup:

set wshShell = CreateObject("WScript.shell") wshShell.sendkeys "{NUMLOCK}"

I'm sure you can adapt it to Perl if needed.

-- TMTOWTDI


In reply to Re: Keyboard Lights by trantor
in thread Keyboard Lights by Superlman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.