Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Keyboard Lights

by Superlman (Pilgrim)
on Sep 30, 2001 at 19:28 UTC ( [id://115733]=perlquestion: print w/replies, xml ) Need Help??

Superlman has asked for the wisdom of the Perl Monks concerning the following question:

This might seem rather frivilous, but I'm wondering how to cause the keyboard lights ({Num | Caps | Scroll } Lock) to turn on or off. (It doesn't really matter to me if the corresponding function goes on or off, I just want to play with the lights)

(And, in anticipation of at least one sarcastic comment, I do mean in Perl, not by pushing the appropriate keys)

Replies are listed 'Best First'.
Re: Keyboard Lights
by trantor (Chaplain) on Sep 30, 2001 at 20:29 UTC

    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

      True enough, this script works on Win2k / AS Perl 628 and so does the one-liner

      #! perl -w use strict; use Win32::OLE; my $wshShell = Win32::OLE->new('WScript.shell'); $wshShell->sendkeys("{NUMLOCK}"); __END__ perl -MWin32::OLE -e "Win32::OLE->new('WScript.shell')->sendkeys('{NUM +LOCK}')"
      Rudif
        It works fine on NT4 as well and it's kinda cool too. But how d'ya know whether the lines turned off ?
        Heureux qui, comme Ulysse, a fait un beau voyage Ou comme celui-là qui conquit la Toison, Et puis est retourné plein d'usage et raison, Vivre entre ses parents le reste de son âge!

        J. du Bellay, poëte angevin

Re: Keyboard Lights
by maverick (Curate) on Sep 30, 2001 at 20:22 UTC
    This depends platform to platform I imagine. Under Linux there is the 'setleds' command (man setleds). You could wrap a system call around that. As for doing it purely in Perl, I don't know of a way.

    HTH

    /\/\averick
    perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

Re: Keyboard Lights
by Ido (Hermit) on Oct 01, 2001 at 05:59 UTC
    The C code would be something like:
    #include <dos.h> void main(void) { int num,caps,scroll; num=64; caps=32; scroll=16; pokeb(0x40,0x17,peekb(0x40,0x17)|num|caps|scroll); }
    That's my very very first time touching C(After "Hello World",I bet it's well seen, sorry), but it should work. You could try using Inline.pm to embed it in the Perl code... Also the |s don't have to be |s, they might be ^s or &s for other effects.
Re: Keyboard Lights
by Sigmund (Pilgrim) on Sep 30, 2001 at 21:27 UTC
    Hello!
    I read about an assembly program playing with keyboard light interrupts, but you would be *Really* cool if you did it in Perl!

    SiG
Re: Keyboard Lights
by zuqif (Hermit) on Oct 01, 2001 at 11:46 UTC
    I did something similar in C on Solaris many moons ago to exec as part of my logout .. will dig out and post, but it definitely happened after reading man ioctl.

    The posted Win32 code dont seem to run under Win98 ..

    Mine first post!?
    the 'qif;

    nyaph

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://115733]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found