Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
5.00/5 (1 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
:)
Posted
Comments
[no name] 7-Dec-12 9:17am    
+5
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

 
Share this answer
 
v2
Comments
sariqkhan 7-Dec-12 9:32am    
sir,
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
At the top of your class put
using System.Runtime.InteropServices;
...
		[DllImport("user32.dll")]
		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);
keybd_event(CAPSLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,(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
http://msdn.microsoft.com/en-gb/library/windows/desktop/dd375731(v=vs.85).aspx[^]
 
Share this answer
 
v2
Comments
CHill60 7-Dec-12 10:35am    
With thanks to Michael Nemtsev at http://bytes.com/topic/c-sharp/answers/464602-possible-turn-off-caps_lock 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    
+5

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900