CodeItBetter Programming Another VB Programming Blog

How to get the NumLock state whether it is on or off

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'System & API - How to get the NumLock state whether it is on or off

Option Explicit
 
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
 
Public Function NumLockOn() As Boolean
    'This function will tell us whether the capslock is on or off
    Dim iKeyState As Integer
    iKeyState = GetKeyState(vbKeyNumlock)
    NumLockOn = (iKeyState = 1 Or iKeyState = -127)
End Function
 
'How can I call this function:
Sub Main()
    If NumLockOn Then
        Call MsgBox("NumLock is On", vbInformation, App.Title)
    Else
        Call MsgBox("NumLock is Off", vbInformation, App.Title)
    End If
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.