Get the current state of the CapsLock, NumLock, or ScrollLock keys
Option Compare Database
Option Explicit
' Disclaimer: I haven't tested this on 64-bit yet. Let me know if you have problems
#If VBA7 Then
Public Declare PtrSafe Function GetKeyState Lib "user32" (ByVal myKey As Long) As Integer
#Else
Public Declare Function GetKeyState Lib "user32" (ByVal myKey As Long) As Integer
#End If
Private Const KeyNumLock = &H90
Private Const KeyCapsLock = &H14
Private Const KeyScrollLock = &H91
Function GetCapsLock() As Boolean
GetCapsLock = CBool(GetKeyState(KeyCapsLock) And 1)
End Function
Function GetNumLock() As Boolean
GetNumLock = CBool(GetKeyState(KeyNumLock) And 1)
End Function
Public Function GetScrollLock() As Boolean
GetScrollLock = CBool(GetKeyState(KeyScrollLock) And 1)
End Function
Usage:
If GetCapsLock()=TRUE then DoSomeStuff