By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

Detect whether Caps Lock key pressed?

P: n/a
yxq
Hello,
I have a main form, there other some controls(i.e. textbox) in the form.
I want to detect whether Caps Lock key is pressed in form-key event.

Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = 20 Then
MessageBox.Show("Caps Lock is pressed!")
End If
End Sub

But the code will not work, how to do? I guess the other controls accepted
the key?

Thank you
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Use the getkeystate api. It will return true if the key is
active.
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As
boolean

Const VK_NUMLOCK = 144

Const VK_CAPLOCK = 20

Ken

------------------
"yxq" <ga***@163.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hello,
I have a main form, there other some controls(i.e. textbox) in the form.
I want to detect whether Caps Lock key is pressed in form-key event.

Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = 20 Then
MessageBox.Show("Caps Lock is pressed!")
End If
End Sub

But the code will not work, how to do? I guess the other controls accepted
the key?

Thank you

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.