Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Keyboard Lights

by trantor (Chaplain)
on Sep 30, 2001 at 20:29 UTC ( [id://115738]=note: print w/replies, xml ) Need Help??


in reply to Keyboard Lights

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

Replies are listed 'Best First'.
Re: Re: Keyboard Lights
by Rudif (Hermit) on Oct 01, 2001 at 01:59 UTC
    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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-19 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found