Re: VBA method to detect state of CAPSLOCK key?

  • Thread starter Thread starter Tom Ogilvy
  • Start date Start date
T

Tom Ogilvy

Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long




Function CapsLock() As Boolean

Dim Res As Long
Dim KBState(0 To 255) As Byte

Res = GetKeyboardState(KBState(0))
CapsLock = KBState(&H14) And 1


End Function

Usage:

Sub ShowCapsLockState()
msgbox "Caps Lock on? " & capslock
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top