Click here to Skip to main content
14,336,236 members
Rate this:
Please Sign up or sign in to vote.
See more:
as my friend is doing a project, he is facing difficult in enabling the keyboard lights to on and off in a form,
but the simple logic which i get to set the lED on and off in a windows form is pressing the these keys programmatically,
i want to press scroll , caps and num keys programmatically so that LED on the keboard will be turn On and then off, i dont know how to do that, i am a newbie and a student.
thanks in advance,
please help
Krunal Rohit 7-Dec-12 9:17am
sariqkhan 7-Dec-12 9:27am
+5 for what?
fjdiewornncalwe 7-Dec-12 10:02am
It means that Krunal Rohit likes your question. He has upvoted your question. The common way for a CP member to relay this to you is by writing +5. Cheers.
sariqkhan 7-Dec-12 10:09am
:) thank you.
but can you help me in this?
do you have done this before? i am asking about the question which i have asked
Rate this:
Please Sign up or sign in to vote.

Solution 1

sariqkhan 7-Dec-12 9:32am
first example is of reading the status
i just want to press these keys programmatically.
i dont want user to press these keys, it shows the effect like when windows XP starts up it starts these LEDs for better effect
Rate this:
Please Sign up or sign in to vote.

Solution 2

At the top of your class put
using System.Runtime.InteropServices;
		static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
		UIntPtr dwExtraInfo);
		const int KEYEVENTF_EXTENDEDKEY = 0x1;
		const int KEYEVENTF_KEYUP = 0x2;
		const int CAPSLOCK = 0x14;
		const int NUMLOCK = 0x90;
		const int SCROLLLOCK = 0x91;

Then to use it ..
keybd_event(CAPSLOCK, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);

I think this function has been superceded now so you might want to do a bit of googling and improve on this (I'm using quite an old version of Visual Studio at the moment).

Full list of key codes is at[^]
CHill60 7-Dec-12 10:35am
With thanks to Michael Nemtsev at for example code
sariqkhan 7-Dec-12 10:50am
thanks sir
i have found the same code from goodle around 15 mins bfore.
But this is not the production level code,
can you tell me if user press down key then we detect if from keypress event or keydown or other event.. Then using the detection code, and if i want to press the caps key then what will be the code for caps?? Then that code will be implemented in form load event
I think this will be the simple
CHill60 7-Dec-12 12:08pm
Not sure what you mean by "not the production code". You can use the key events to determine if a user has hit a key - but I thought you didn't want them to?
sariqkhan 7-Dec-12 14:09pm
i have done that
thanks to you sir
thank you very much
sariqkhan 7-Dec-12 14:10pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100