0

I would like my login form to display a message when the user logging in
pressed the CAPSLOCK key when he is entering data in the password textbox.

I tried using this code on Keypress Event

If KeyAscii >= 65 And KeyAscii <= 90 Then
   txtPass.Locked = True
   Msgbox "CAPSLOCK Pressed."
Else
   txtPass.Locked = False
End If

but doesn't work when I tried it.

I also see some codes like GetKeyboardState API but I don't really know
how to use that. :$

Thanks in advance.
Code snippet much appreciated.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by AndreRet
0

Fairly easy one.;)

If GetKeyState(vbKeyCapital) = 0 Then
    txtPass.Locked = False
        Else
    txtPass.Locked = True
    Msgbox "CAPSLOCK Pressed."
End If
0

Sorry it needs to go with the API as well in a module -

Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.