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

Related posts:

  1. How to get the CapsLock state whether it is on or off
  2. How to Toggle Num Lock (in two ways)
  3. How to Toggle CapsLock (in two ways)
  4. How to Check whether Mouse exist or not
  5. How to check whether you are connected with internet
  6. How to Check the KeyState of the supplied Key
  7. How to check the window state of an external application
  8. How to find whether the given directory is empty (in three ways)
  9. How to get Total Disk Space for a given drive
  10. How to get the command line arguments using the Command() function?

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.