Solved

How can I turn NumLocks on and off in VB6?

Posted on 2012-04-04
6
361 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:lthames
Comment Utility
trying the sample now.
0
 

Author Comment

by:lthames
Comment Utility
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
Comment Utility
Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now