Click here to Skip to main content
11,716,249 members (86,178 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
Smile | :)
Posted 7-Dec-12 3:00am
sariqkhan1.4K
Comments
Krunal Rohit at 7-Dec-12 9:17am
   
+5
sariqkhan at 7-Dec-12 9:27am
   
+5 for what?
Marcus Kramer at 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 at 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: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v2
Comments
sariqkhan at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
v2
Comments
CHill60 at 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 at 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 at 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 at 7-Dec-12 14:09pm
   
i have done that
thanks to you sir
:)
thank you very much
sariqkhan at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 599
1 Richard MacCutchan 280
2 Maciej Los 275
3 OriginalGriff 160
4 F-ES Sitecore 145
0 Sergey Alexandrovich Kryukov 1,003
1 Richard MacCutchan 430
2 CHill60 415
3 Maciej Los 399
4 OriginalGriff 385


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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