Hi,
How to enable caps locks in my app. so that caps is always on in my app. and that the user cannot turn it off.
Printable View
Hi,
How to enable caps locks in my app. so that caps is always on in my app. and that the user cannot turn it off.
Turn On Caps Lock : http://support.microsoft.com/?id=177674
User cannot turn it off : Don't know. Here is an alternative,
set the form's KeyPreview = True at design time.
Then in the form's Form_KeyDown event turn on the Caps Lock.
WHY WOULD YOU WANT TO DO THAT?Quote:
Originally Posted by greenba
It can be done like this
VB Code:
Const VK_CAPITAL = &H14 Const VK_NUMLOCK = &H90 Const VK_SCROLL = &H91 Private Type KeyboardBytes kbByte(0 To 255) As Byte End Type Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer Private Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long Dim kbArray As KeyboardBytes Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyCapital Then TurnOn VK_CAPITAL End If End Sub Private Sub Form_Load() TurnOn VK_CAPITAL End Sub Private Sub TurnOn(vkKey As Long) 'Change a key kbArray.kbByte(vkKey) = 1 'Set the keyboard state SetKeyboardState kbArray End Sub
@guyvdn
The problem with SetKeyboardState is, it will set the Caps Lock state correctly, but it will not turn on keyboard LED on Win2000/XP systems. It may confuse the user.
On Win200/XP systems, we need to simulate a keypress using keybd_event.
:wave:
is there really a need for you to have the caps lock always on. if its just for a few textboxes, used the keypress event of the textbox
VB Code:
private sub text1_keypress(keyascii as integer) keyascii = asc(ucase(chr(keyascii))) end sub
I didn’t notice that, I have a wireless keyboard and the leds are on a docking station that’s urm somewhere on my desk ;)Quote:
Originally Posted by iPrank
If you set keypreview of the form to true you can use the keypress event of the form. You only have to write the code once and it will work for all the controls. But the keyboard LED will also not be turned on.Quote:
Originally Posted by d3gerald
PS2 or USB keyboard ? Mine is a plain PS2.
May be other members can give more different 'input'. :D
I wouldn't do this. I wouldn't want Users to get annoyed when they CAPS lock turned on even when they didn't do anything. If you actually need UpperCase characters in your application, then you can always use UCase$ to convert the text in UpperCase. But doing unexpected is not what Users like.Quote:
Originally Posted by greenba