views:

804

answers:

3

What is a method to detect if NumLock is OFF and how to turn it always back ON automatically when my VB APP is running ?

EDIT: My app is dedicated app, running on dedicated computer with external numpad device.

another option would be to ACCEPT NUMPAD ARROW KEYS (etc) and convert these to NUMBERS on fly, is it possible?? (e.g. ignore the numlock off situation and behave as numlock is on)

+2  A: 

I'm not sure how you do this specifically in vb.net (a quick google found http://support.microsoft.com/kb/177674), but generally speaking changing machine-wide settings like this is frowned upon: users are accustomed to their individual preference for numlock (or capslock -- or whatever) key state...and you're overriding it.

This would really irritate me.

That said, in circumstances where your app is the only thing running (e.g., POS software, medical office management software, etc) this might be ok.

DarkSquid
Could not agree more on the irritation factor. @OP: Please don't do this unless your app has complete and exclusive control of the machine.
Software Monkey
this is dedicated app in dedicated machine. It will have a unique external NUMPAD as only keyboard, it would be catastrof if user click numlock off by mistake.. any ideas?
Tom
Process the key-codes with + without numlock. So, it doesn't matter whether it is on or not.
sybreon
+1  A: 

Physically remove NUMPAD key ?

Catalin DICU
well, I was looking for programming solution.. but figured out my own now..
Tom
...some sort of electric shock device on the NumLock???
kevchadders
+1 for creativity!
sybreon
I need some sort of electric shock device on my numlock key at work, so when my boss uses my computer for something, he'll be, um, reminded not to turn it off. :) (I keep telling him there are perfectly serviceable arrow keys just an inch or two away, there's no need to misappropriate my number keys, but he doesn't believe me.)
Martha
+1  A: 
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Const KEYEVENTF_KEYUP = &H2
    Const VK_NUMLOCK = &H90
    Const KEYEVENTF_EXTENDEDKEY = &H1
    Declare Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal ByValnVirtKey As Integer) As Short

 Private Sub numlockON()
        keybd_event(VK_NUMLOCK, 0, 0, 0) ' Press NUMLOCK key down
        keybd_event(VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0) ' Release it
    End Sub

If Not GetKeyState(VK_NUMLOCK) Then numlockON()
Tom