hi
Form load Caps Lock turn on....
How to do?
plzz help
Printable View
hi
Form load Caps Lock turn on....
How to do?
plzz help
Found these links about caps lock. C++ example seems to show how to turn it on, but only c# example was more about monitoring the state
C++ Turn Caps Lock On
http://www.greatis.com/delphicb/tips...apslockon.html
Monitor Key States
http://www.codecomments.com/archive2...-5-489956.html
I'm not sure how to toggle Caps Lock for the system, but the following code will control it for your app specifically:That code will not change the Caps Lock light on your keyboard or affect any other apps, but it will turn Caps Lock on and off in your app. I would have thought that simply SendKeys.Send("{CAPSLOCK}") would have done the job of toggling Caps Lock for the system but apparently not.VB Code:
Private Const VK_CAPITAL As Integer = 20 Declare Function GetKeyboardState Lib "user32" Alias "GetKeyboardState" (ByRef pbKeyState As Byte) As Integer Declare Function SetKeyboardState Lib "user32" Alias "SetKeyboardState" (ByVal lppbKeyState As Byte()) As Integer Private Sub onButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles onButton.Click Dim keyState(255) As Byte Me.GetKeyboardState(keyState(0)) keyState(VK_CAPITAL) = 1 Me.SetKeyboardState(keyState) End Sub Private Sub offButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles offButton.Click Dim keyState(255) As Byte Me.GetKeyboardState(keyState(0)) keyState(VK_CAPITAL) = 0 Me.SetKeyboardState(keyState) End Sub
This would work in C#?Quote:
Originally Posted by jmcilhinney
Oops. I forget I'm in the C# forum sometimes. Here's the direct translation, which I've tested and it works:Code:private const int VK_CAPITAL = 0x14;
[DllImport("user32.dll")]
private static extern int GetKeyboardState(ref byte pbKeyState);
[DllImport("user32.dll")]
private static extern int SetKeyboardState(byte[] lppbKeyState);
private void onButton_Click(object sender, System.EventArgs e)
{
byte[] keyState = new byte[256];
GetKeyboardState(ref keyState[0]);
keyState[VK_CAPITAL] = 1;
SetKeyboardState(keyState);
}
private void offButton_Click(object sender, System.EventArgs e)
{
byte[] keyState = new byte[256];
GetKeyboardState(ref keyState[0]);
keyState[VK_CAPITAL] = 0;
SetKeyboardState(keyState);
}