• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

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!
0
lthames
Asked:
lthames
  • 4
  • 2
1 Solution
 
vb_elmarCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now