Gold mine of Visual C++ tricks!
How to blink LED's in Keyboard?
![]()
Do you remember those golden DOS days, where we access the video RAM directly and set the status of NumLock, ScrollLock etc and blink the LED of keyboard. Now in modern windows environment we are no more allowed to access the video RAM directly. But is there any way to blink the keyboard LEDs as we did before?

![]()
Yes. The trick is to send NumLock keystroke event by using keybd_input() function. See the sample code snippet from MSDN.
// Set NUMLOCK Status.
void SetNumLock( BOOL bState )
{
BYTE keyState[256];
GetKeyboardState((LPBYTE)&keyState);
if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
(!bState && (keyState[VK_NUMLOCK] & 1)) )
{
// Simulate a key press
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
// Simulate a key release
keybd_event( VK_NUMLOCK,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
}
// Blink NUMLOCK.
void BlinkNumLock()
{
// Blink status.
bool bBlink = false;
// Blink the NUMLOCK periodically.
while( true )
{
SetNumLock( bBlink );
bBlink = !bBlink;
Sleep( 100 );
}
}
![]()
You can also use SendInput(), which is the latest version of keybd_event() to simulate keystrokes.
And one more thing, I was searching for an image for this post, but couldn’t find a suitable one. And this image is suggested by my wife.
How is it? Did you like it? She would like to hear from you
![]()
Targeted Audiance – Intermediate.
| Print article | This entry was posted by Jijo Raj on March 12, 2009 at 5:53 pm, and is filed under Visual C++. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
Oh, it’s a very magnificent image with dark gray… no!, white! circles
about 1 year ago
Hi AtHeven,
Keep Watching!
Thanks a lot!!! My wife is so happy to hear those words!
Regards,
Jijo.
about 1 year ago
It took me a little while to understand why the picture was special for any reason until I went back and scanned it with my eyes. For me, when I focused on one white dot, all the other dots in my peripheral where a kind of blacked spotted outline of the circle shape. Scanning across the image makes the dots appear to blink. Maybe I had too much to drink last night.
about 1 year ago
Hi Mfweb,
Indeed, that pic is a bit special. Its an illusion in which the dot seems blinking, which i think is an ideal one for the article. Well, keep watching buddy! A lot of good tips and nice images are waiting for you!
Regards,
Jijo.
about 1 year ago
very intresting
about 9 months ago
Tell your wife excellent choice of images!
-Ben
about 9 months ago
Sure Ben! She will be happy to hear that.
Best Regards,
Jijo.
about 6 months ago
New to weseetips.com and thought, what could be a better way to introduce myself than give my best regards to you all
[url=http://www.shaggybevo.com/forums/profile.php?mode=viewprofile&u=4395 ][img]http://www.forex1st.com/forex-trading.gif[/img][/url]