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.

Fairly easy one.;)

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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.