I know this should be pretty damn easy. I need to know how to turn on the Cap key through the code. I know I should use setkeyboardstate but I just don't know the rest of the command for this API.
Printable View
I know this should be pretty damn easy. I need to know how to turn on the Cap key through the code. I know I should use setkeyboardstate but I just don't know the rest of the command for this API.
I don't know the API call for this, but you could cheat by using the following
On the form, turn on the keypreview property at design time
in form_keypress enter the following code
private sub Form_Keypress(KeyAscii as Integer)
keyascii=asc(ucase(chr(keyascii)))
end sub
This will make sure that every letter pressed is in upper case and means that if the user turns off the caps lock when you don't want them to it doesn't matter
All this does is converts the keyascii value (ASCII value of the key) to the charector (Chr(KeyAscii)), converts this to uppercase (Ucase(chr(keyAscii))) and converts it back to as ASCII code (asc(ucase(chr(keyAscii)))
All the keypreview property does is makes sure that the forms key events are processed before the controls key events
Hope this helps
Chris
This code is supposed to do it, but it was not working right for me.
Hope this works for yaCode:SendKeys "{capslock}"
'vb6
'capitalize all small case letters
'
If Chr(KeyAscii) >= "a" And Chr(KeyAscii) <= "z" Then
KeyAscii = KeyAscii - 32
End If
'
here's a routine I use which is originally based upon a KPD Team example :
Code:Option Explicit
Const KB_CAPITAL = &H14
Private Type Key_Bytes
KeyState(0 To 255) As Byte
End Type
Private Declare Function GetKeyboardState Lib "user32" (Key_Array As Key_Bytes) As Long
Private Declare Function SetKeyboardState Lib "user32" (Key_Array As Key_Bytes) As Long
Dim Key_Array As Key_Bytes
Private Sub Main()
CapsOn
CapsOff
End Sub
Private Sub CapsOn()
GetKeyboardState Key_Array
Key_Array.KeyState(KB_CAPITAL) = 1
SetKeyboardState Key_Array
End Sub
Private Sub CapsOff()
GetKeyboardState Key_Array
Key_Array.KeyState(KB_CAPITAL) = 0
SetKeyboardState Key_Array
End Sub
Paul,
How about the NumLock key, what is the constant value?
The ones that I can find are :
Const KB_CAPITAL = &H14
Const KB_NUMLOCK = &H90
Const KB_SCROLL = &H91
Hope this helps.