Solved

How can I turn NumLocks on and off in VB6?

Posted on 2012-04-04
6
364 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

831 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