How can I turn NumLocks on and off in VB6?

Is there a way to turn the NumLocks on and off in VB6 (classic vb)?

Thanks!
lthamesAsked:
Who is Participating?
 
vb_elmarConnect With a Mentor Commented:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const VK_NUMLOCK = &H90
Const KEYEVENTF_KEYUP = &H2

Private Sub Command1_Click()
    keybd_event VK_NUMLOCK, 0, 0, 0
    keybd_event VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0
End Sub
0
 
vb_elmarCommented:
The following sample checks the numlock state and
if the state is "1" (=numlock enabled) it turns numlock "off".
Please set the "timer1.interval" to 1000

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const VK_NUMLOCK = &H90
Const KEYEVENTF_KEYUP = &H2
Private Declare Function Tasten_Status1 Lib "user32" Alias "GetKeyState" (ByVal nvirtkey As Long) As Integer

Private Sub Timer1_Timer()
ts = Tasten_Status1(144)
Caption = ts '0(numlock disabled) or 1(numlock enabled)

If ts = 1 Then
    keybd_event VK_NUMLOCK, 0, 0, 0
    keybd_event VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0
End If
End Sub
0
 
lthamesAuthor Commented:
That doesn't work for me.

I put the first 3 lines in my declarations and added a command button to insert the other code in.

It never changed the status of my caps lock.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
lthamesAuthor Commented:
trying the sample now.
0
 
lthamesAuthor Commented:
I am an idiot . . . . I was testing caps lock, not num lock.  It does work.

Thank you very much!!!!!!!!
0
 
lthamesAuthor Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.