![]() |
| | #1 |
| Registered User Join Date: Nov 2006
Posts: 39
| How to detect that capslock in on in C# How to detect that capslock in on in C# and How to Close it!! |
| obaid is offline | |
| | #2 |
| Registered User Join Date: Mar 2005 Location: Mountaintop, Pa
Posts: 1,059
| Code: using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class CapsLockControl
{
[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;
public static void Main()
{
if (Control.IsKeyLocked(Keys.CapsLock))
{
Console.WriteLine("Caps Lock key is ON. We'll turn it off");
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr) 0);
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
(UIntPtr) 0);
}
else
{
Console.WriteLine("Caps Lock key is OFF");
}
}
}
|
| BobS0327 is offline | |
| | #3 |
| Registered User Join Date: Nov 2006
Posts: 39
| thankz budy!! i will try this code.. thank you, again |
| obaid is offline | |
| | #4 | |
| Registered User Join Date: Dec 2006
Posts: 12
| Hi Bob, This piece of code is really wonderful....but i didn't get the details of it... can you provide me any good links from where i can learn such dll programming ? Thank you Quote:
| |
| sangfroid is offline | |
| | #5 |
| System Novice Join Date: Jan 2006 Location: Tehran
Posts: 1,210
| You should avoid this kind of code. Using Control.IsKeyLocked(Keys.CapsLock) has no problem. But calling a function in a system DLL should be avoided as long as possible. You can make all letters capitel or lower case in a control input.
__________________ Learn C++ (C++ Books, C Books, FAQ, Forum Search) Code painter latest version on sourceforge DOWNLOAD NOW! Download FSB Data Integrity Tester. Shareaza Ultimate P2P Siavosh K C |
| siavoshkc is offline | |
| | #6 |
| Super Moderator Join Date: Aug 2001
Posts: 8,423
| Yes while this works I wouldn't think it's the best approach from a C# standpoint. I believe this information is provided to you in the key down/up handlers. |
| Bubba is offline | |
| | #7 |
| Registered User Join Date: Mar 2005 Location: Mountaintop, Pa
Posts: 1,059
| Here is Microsoft's approach to toggling the caps lock key in VB. Please note that the VB example is using pinvoke. So, you'll have to translate VB to C#. Also, virtual keys such as the caps lock aren't processed in the key up and keydown handlers. Here is a link to a platform invoke tutorial. Please note that C# has very little capability to address system level issues. For instance, if you're writing a C# GUI that will do network monitoring, a lot of your code will be pinvoke code. Reason being, C# does not have the "native" ability to ping a workstation to determine if it is on the network. C# does not have the "native" ability to query the remote workstation's available hard drive space. C# does not have the "native" ability to query the total uptime of the remote workstation. C# does not have the "native" ability to determine who is logged on to the remote workstation. I could go on and on. So, pinvoke to is used to more or less "flesh out" an application if you're doing any type of systems level programmingl. You can also use this same argument for the advanced GUI (GDI) drawing. Here is link to a lot of pinvoke info. |
| BobS0327 is offline | |
| | #8 | |
| System Novice Join Date: Jan 2006 Location: Tehran
Posts: 1,210
| Quote:
__________________ Learn C++ (C++ Books, C Books, FAQ, Forum Search) Code painter latest version on sourceforge DOWNLOAD NOW! Download FSB Data Integrity Tester. Shareaza Ultimate P2P Siavosh K C | |
| siavoshkc is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to Write a Program in C to detect the Ethernet Cable? | christyyim | C Programming | 1 | 03-11-2009 04:12 AM |
| Detect Running Programs? | MattKamil | Windows Programming | 2 | 07-03-2006 06:13 AM |
| Edge Detect | 250co | C Programming | 0 | 05-22-2006 08:51 PM |
| detect variable overflow | surdy | C Programming | 9 | 05-13-2004 12:49 PM |
| Using RS232 25pin i need a program to detect magnitude and frequency of lightning | ajastru2000 | C++ Programming | 5 | 11-20-2003 01:27 AM |