kbay808
asked on
How to turn on numlock via VBS code?
For some reason my code is turning off numlock and I need a way to make sure it's turned back on.
ASKER
How can I check to make sure that numlock is off? I don't want it to turn it off if it happens to be on.
Is the code you want to add this too VBScript, or VBA?
»bp
»bp
Also, as I reread this, I suppose another approach is to figure out where your code is turning off numlock, and stop that from happening. If doable that would be a better solution than trying to determine the state before you ran, and then restore that state afterwards.
What can you tell us about the application and the code involved?
»bp
What can you tell us about the application and the code involved?
»bp
ASKER
The issue is when using sendkeys
ASKER
I use this code in VBA. Is there is version that will check in VBS?
If GetKeyState(NumlockKey) = 0 Then
SendKeys "{NUMLOCK}"
End if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@ Shaun Vermaak - for some reason that link won't open for me, but I would rather not use word if possible.
@ Bill Prew - That work great. Thanks
@ Bill Prew - That work great. Thanks
ASKER
Thank you
And you could package that in a small function that returns a logical variable for IF test, like:
»bp
If GetNumlockState() = True Then
Wscript.Echo "Numlock is ON"
Else
Wscript.Echo "Numlock is FF"
End If
Function GetNumlockState()
strResult = WScript.CreateObject("WScript.Shell").Exec("powershell.exe -command [console]::NumberLock").StdOut.ReadLine
If strResult = "True" Then GetNumlockState = True Else GetNumlockState = False
End Function
»bp
Great, glad we got to a working solution, that took some thinking but was fun, thanks for the feedback.
»bp
»bp
Open in new window