What I want to do is pretty simple and it would be very nice as a winAMP plugin ... First of all I just need an analyser to see the frequencies outputed by winamp ( but this is not important for me now )

I've read a long time ago that we could change the state of the keyboard's led by changing some value directly in the BIOS Memory ...

I don't want to end up a solution in which it wil disturb the user ... example if he types text I don't want that the cap lock will be turned on just by changing the led's state ...

If it's possible tell me ... by the way some example of changing values in BIOS would be needed since I don't know too much in that area !

Thank you
Posted on 2001-08-13 20:28:08 by JP?
It is a farily simple thing to do, except it also means writing directly to the keyboard ia IO ports, so woulnd't work under NT or 2000. If there is an API somewhere which allows the same thing I dont know of it. But here is how I would do it:

This simple little prog will flash the 3 leds 10 times.


include \masm32\include\windows.inc

include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib


WinMain PROC

mov edi,10 ;Loop 10 times

invoke KeyBDIOCheck ;This little proc makes sure the keyboard controller is ready to be written to
mov al,0edh ;Command, set LED lights
out 60h,al ;Send it to the keyboard

invoke KeyBDIOCheck ;Wait for ready
mov al,0111b ;Set all 3 lights (lowest 3 bits set)
out 60h,al ;Send it

invoke Sleep ,1000 ;Wait for 1 second

invoke KeyBDIOCheck ;Wait again
mov al,0edh ;Set LED lights
out 60h,al ;Send it

invoke KeyBDIOCheck ;Wait for ready
xor al,al ;No bits set, all lights off
out 60h,al ;Send it

invoke Sleep ,1000 ;Sleep

dec edi ;Decrement counter
jnz MainLoop ;Loop if counter not zero

invoke ExitProcess ,NO_ERROR
WinMain ENDP

;This procedure check to make sure the keyboard controller is
;ready to be written to, ie so it wont corrupt data already written
;to the controller

in al,64h ;Get the status BYTE
.IF (al & 010b) ;Check the 2nd bit (Write ready)
mov eax,0fffh ;If its set have a slight delay
dec eax
jnz @B
jmp ReadyForWrite ;Try again


END WinMain
Posted on 2001-08-14 01:38:45 by huh
ummm that winamp plugin exists... or well atleast it used to... just thought i'd mention that
Posted on 2001-08-14 02:55:52 by NervGaz
Nergaz, I don't care if it's already existing .. it's for learning purpose :) you know :alright:
If you find that plugin could you email it to me ?

Is there a way to write to the memory of a single LED ie. changing the state of one led ?

Thank you Huh for your help and source code !

Posted on 2001-08-14 11:00:27 by JP?
This is what I have found in an old programming site !


Set/reset status indicators. This command allows you to control the status LEDs on the keyboard. Keyboard responds with ACK and waits for a option byte, bitmapped as follows: b0-Scrollock, b1-Numlock, b2-Capslock, b3..7=0. A '1' bit turns the indicator ON.

It seems that it would do what I want but I don't seem to understand it's usage ...

I've tried to replace in your code the 0111b with EDB0 but it doesn't turn the numlock on ... and we need to send the bit 1 to turn it on .... I don'T understand how to do it ?

Posted on 2001-08-14 11:50:37 by JP?
AAHAHHHAHHAAHAH :grin: It was so easy ..... !!!! the reason why it didn't work is because I didn't save the changes .... because in BCB IDE and Delphi it is automaticcaly saved into a buffer while compiling ( it compiles what you see not what you have saved )

Thank you all !

--Hutch, It would be great to implement that function in you editor :)

Posted on 2001-08-14 12:01:51 by JP?
you're all making things very difficult. the solution is very easy and can be done with window's APIs. first call

invoke GetKeyboardState,addr keybarray

keybarray is an array of 256 bytes. this API stores the status of every key in this array (0=off, 1=on). if you for example want to change the keystatus of CAPSLOCK, change the VK_CAPITAL member of the array to 0 or 1 (depending on what you want to do). so you can use the VK-constants to get the correct member of the array. then simply call:

invoke SetKeyboardState,addr keybarray

that's all, easy, isn't it?

Posted on 2001-08-14 12:12:42 by NOP-erator
Yeah NOP .. but won't your technique affect user's input ...

example if with VK_CAPITAL you put 1 .. to open the LED
when the user will type something it will become with CAPITAL LETTERS ... won't it ? :confused:

Posted on 2001-08-14 15:46:58 by JP?
heh... I remember the winamp plugin doing that... hehe LeEt SpEAk :grin: anyways if you're still interested in it it's around on the winamp site
Posted on 2001-08-15 02:07:16 by NervGaz
I thought, that ring 3 applications are not allowed to do direct IO under Win9x. Even Iczelions VXD tut#1 says: ??application programs are restricted in what they can do to the system. They cannot use privileged CPU instructions, they cannot access I/O port directly and so on??.

But huh?s code above works just fine. Why does Win9x allow direct IO access for applications? Isn?t this what the VXD:s are for, partly?

What comes to using the leds for something that they are not ment for, I guess it?s not very good idea. If there is a lot of IO with port 60 because of rapid blinking of the leds, at some point it must affect the usability of the keyboard. But if for some reason this is not the case, another use for the leds could be also using one of them as HDD activity led.
Posted on 2001-08-15 07:17:31 by Janne
hey JP?,
actually i don't know if it does affect user input. sorry.

Posted on 2001-08-15 12:28:05 by NOP-erator
hey JP?,
I'll ask my brother tomorrow if he can give me a program that simulates a "lichterkette" (chain of lights) on the keyboard. he sais that it doesn't affect user input, but he isn't sure. i'll tell you more tomorrow. perhaps you can try to find out what the program does with reverse engineering.

Posted on 2001-08-15 12:31:00 by NOP-erator
Actually the code submitted by Huh was pretty functionnal .... I modified it and it doesn't affect user's inputs. I've build a version called led.exe, it makes the led flashing in a predeterminated order ... it's pretty cool at a speed arounding the 50-75 ms ;)

I've also tested it during 5 hours and it doesn't affect this particuliar I/O port... Also my app doesn't make any overload in memory.

My goal is to turn useless thing into useful stuff .... I plan to add a cpu load analyser + the current spectrum analyer ... also traffic for the internet and maybe and indicator of email :)

Have fun !!

I'll surely post my app on Iczelion's site ;)

Posted on 2001-08-15 13:05:55 by JP?
great! would you mind to send me the "useless" source?


Posted on 2001-08-16 09:29:59 by NOP-erator
The only problem with my code that I have noticed is that if you press a key which changes the state of a LED (eg Caps lock) windows will set all the LEDs back to what they should be.

As for corrupting windows keyboard IO, it shouldn't do _unless_ windows was in the middle of writing a command to the keyboard, and if it switched tasks to your program.
Posted on 2001-08-17 06:56:27 by huh
Then again it still won't work in NT/2K... :mad:
Posted on 2001-08-17 08:02:04 by NervGaz

not that it's much use, but......

there was a little tool I used to use in Linux called tleds, which showed network traffic on the keyboard leds, and didn't affect user input.

Posted on 2001-08-17 20:20:49 by Fourfty