Here's how you can do it with Inline under linux (the only OS I tested). You need the appropriate perms to the console so YMMV (also, most error checking removed for brevity sake).

(original Inline code)

#!/usr/bin/perl use Inline C; use strict; toggle_lights(); __END__ __C__ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/ioctl.h> #include <sys/kd.h> #define ERROR -1 void toggle_lights() { int fd; int i = 0; long int orig = 0; if ((fd = open("/dev/console", O_NOCTTY)) == ERROR) { perror("cannot open console"); exit(ERROR); } ioctl(fd, KDGETLED, &orig); i |= LED_NUM; ioctl(fd, KDSETLED, i); sleep( 2 ); i = 0; i |= LED_CAP; ioctl(fd, KDSETLED, i); sleep( 2 ); i = 0; i |= LED_SCR; ioctl(fd, KDSETLED, i); sleep( 2 ); ioctl(fd, KDSETLED, orig); }

-derby

Update: Whoa! I forgot that ioctl is normally available under pure perl. I hade to steal the KD_* and LED_* constants from the include file but it works fine.

(buggy pure perl code)

#!/usr/bin/perl require "sys/ioctl.ph"; open( FH, "/dev/console" ) || die "cannot open console"; $KDSETLED = 0x4B32; $KDGETLED = 0x4B31; $LED_SCR = 0x01; $LED_NUM = 0x02; $LED_CAP = 0x04; ioctl(FH, $KDGETLED, $orig); $i = 0; $i |= $LED_NUM; ioctl(FH, $KDSETLED, $i); sleep( 2 ); $i = 0; $i |= $LED_CAP; ioctl(FH, $KDSETLED, $i); sleep( 2 ); $i = 0; $i |= $LED_SCR; ioctl(FH, $KDSETLED, $i); sleep( 2 ); ioctl(FH, $KDSETLED, $orig);

Update (again): Noticed a small bug in the above perl code when resetting the lights back to original. Here it is again:

#!/usr/bin/perl require "sys/ioctl.ph"; open( FH, "/dev/console" ) || die "cannot open console"; $KDSETLED = 0x4B32; $KDGETLED = 0x4B31; $LED_NUM = 0x02; $LED_CAP = 0x04; $LED_SCR = 0x01; ioctl(FH, $KDGETLED, $orig); @ary = unpack("ccccs",$orig); foreach $state ( $LED_NUM, $LED_CAP, $LED_SCR, $ary[0] ) { $i = 0; $i |= $state; ioctl(FH, $KDSETLED, $i); sleep( 2 ); }


In reply to Re: manipulating the lights on a keyboard by derby
in thread manipulating the lights on a keyboard by J0hny_Lightning

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.