?
Solved

Can i check the status of Num Lock?

Posted on 1999-12-05
9
Medium Priority
?
224 Views
Last Modified: 2010-05-02
I need to check the status of num lock to make sure that it is on all the time?
0
Comment
Question by:hutchison
  • 4
  • 3
  • 2
9 Comments
 
LVL 5

Expert Comment

by:KDivad
ID: 2256928
Add to declarations section:

Private Declare Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal nVirtKey As Long) As Integer

To check the numlock, use:

If GetKeyState(vbKeyNumLock) = 1 Then
    'NumLock is on
Else
    'NumLock is off
end if

Hope this helps!
0
 
LVL 2

Accepted Solution

by:
cantrell earned 100 total points
ID: 2257036
I had the same problem. This is my app that I wrote and just put in the startup group so it turns it on every time I start up my computer. You could set a timer also if you wanted to. Here is the code...


Public Const VK_NUMLOCK = &H90

Public Type KeyboardBytes
     kbByte(0 To 255) As Byte
End Type

Public kbArray As KeyboardBytes

Public Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long

Public Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long


Sub main()
   
    'Turn numlock on.
    GetKeyboardState kbArray
    kbArray.kbByte(VK_NUMLOCK) = 1
    SetKeyboardState kbArray

End Sub

0
 

Author Comment

by:hutchison
ID: 2257353
I like your proposal kDivad but we have an unusual problem is that it somtimes will turn off by itself during operation so i need to keep checking its value and if it is off then turn it back on. I can see your answer to this cantrell but i was wondering if you had a way of turning it on kDivad.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:hutchison
ID: 2257362
I like your proposal kDivad but we have an unusual problem is that it somtimes will turn off by itself during operation so i need to keep checking its value and if it is off then turn it back on. I can see your answer to this cantrell but i was wondering if you had a way of turning it on kDivad.
0
 
LVL 2

Expert Comment

by:cantrell
ID: 2257461
Use my code above, and just put

    'Turn numlock on.
    GetKeyboardState kbArray
    kbArray.kbByte(VK_NUMLOCK) = 1
    SetKeyboardState kbArray

in a timer event that checks every 10 seconds to a minute.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 2259873
Mine would be the same as cantrell's. I would've posted it but all I noticed was "check the status of num lock" and I failed to see "to make sure that it is on all the time".

Later,
0
 

Author Comment

by:hutchison
ID: 2260911
I have put the major part of your code into a module and the other code into a timer checking every 10 seconds but it doens't work. If i turn num lock of on purpose then it doesn't com eback on. Whats wrong?
0
 
LVL 5

Expert Comment

by:KDivad
ID: 2261133
We forgot one little detail. I've never actually tried them, but I've heard that GetKeyboardState and SetKeyboardState only work in the current thread. I don't know of any other way to actually set the numlock globally.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 2261139
P.S. GetKeyState is also thread-dependent. It seems there isn't any way to correctly get/set the state of the locks from VB. With memory I/O, it's actually a fairly simple matter using Peek and Poke, too bad VB doesn't support them.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

599 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