Solved

How can I turn NumLocks on and off in VB6?

Posted on 2012-04-04
6
362 Views
Last Modified: 2012-04-04
Is there a way to turn the NumLocks on and off in VB6 (classic vb)?

Thanks!
0
Comment
Question by:lthames
  • 4
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
vb_elmar earned 500 total points
ID: 37808483
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
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37808564
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
 

Author Comment

by:lthames
ID: 37808572
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:lthames
ID: 37808576
trying the sample now.
0
 

Author Comment

by:lthames
ID: 37808588
I am an idiot . . . . I was testing caps lock, not num lock.  It does work.

Thank you very much!!!!!!!!
0
 

Author Closing Comment

by:lthames
ID: 37808592
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now