VB Code:
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long Private Const VK_CAPITAL = &H14 Private Const VK_NUMLOCK = &H90 Private Const VK_SCROLL = &H91 ReDim KeyboardBuffer(256) As Byte GetKeyboardState KeyboardBuffer(0) 'This example show you how to press the Caps Lock button. if you want 'to press the Num Lock button, Replace all the following 3 'VK_CAPITAL' 'with 'VK_NUMLOCK' or VK_SCROLL as desired. If KeyboardBuffer(VK_CAPITAL) And 1 Then KeyboardBuffer(VK_CAPITAL) = 0 Else KeyboardBuffer(VK_CAPITAL) = 1 End If SetKeyboardState KeyboardBuffer(0) Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer 'To check if Num Lock is on Replace the 'vbKeyCapital' below with 'vbKeyNumlock' Dim lngWhatState As Long lngWhatState = GetKeyState(vbKeyCapital) If lngWhatState = 1 Then MsgBox "The Caps Lock Is On" Else MsgBox "The Caps Lock Is Off" End If




Reply With Quote