Click to See Complete Forum and Search --> : Caps Lock On
Plucky
Dec 20th, 2005, 11:30 PM
hi
Form load Caps Lock turn on....
How to do?
plzz help
RFKevdog
Dec 21st, 2005, 03:27 PM
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/lib/manipulators-capslockon.html
Monitor Key States
http://www.codecomments.com/archive290-2005-5-489956.html
jmcilhinney
Dec 21st, 2005, 08:51 PM
I'm not sure how to toggle Caps Lock for the system, but the following code will control it for your app specifically: 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 SubThat 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.
Hack
Dec 22nd, 2005, 09:15 AM
I'm not sure how to toggle Caps Lock for the system, but the following code will control it for your app specifically: Private Const VK_CAPITAL As Integer = 20
Declare Function GetKeyboardState Lib "user32" Alias "GetKeyboardState" (ByRef pbKeyState As Byte) As Integer
Declare Function SetKeyboardState Lib o"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 SubThat 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.This would work in C#?
jmcilhinney
Dec 22nd, 2005, 06:27 PM
Oops. I forget I'm in the C# forum sometimes. Here's the direct translation, which I've tested and it works: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);
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.