ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA method to detect state of CAPSLOCK key? (https://www.excelbanter.com/excel-programming/310355-re-vba-method-detect-state-capslock-key.html)

Tom Ogilvy

VBA method to detect state of CAPSLOCK key?
 
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

--
Regards,
Tom Ogilvy

"Jquads" wrote in message
...
I'm not looking for code to turn CAPSLOCK on or off; I simply want to

detect
the state of the CAPSLOCK key.

I'm running Excel10 and 11.

TIA for any suggestions.





All times are GMT +1. The time now is 05:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com