NUM LOCK status

B

Black1

I'm sure I remember reading that this was a know problem in excel 97, but I
don't remember the solution:

I'm building a tool for various users and it's all driven through forms....

however:

when one form closes and another opens the NUM LOCK deselects itself. If I
use sendkeys "{numlock}" it selects it again when I step through the code,
but when I run it, it doesn't work.

I know that numbers can be entered using the number keys above the alpha
keys, but most users use the number pad.

Is there a piece of code that can detect whether NUM LOCK is selected or
not, and reselect it if it isn't?

Thanks
 
B

Black1

Unfortunately I cant get his solution to work, I keep getting

"Can't find DLL entry point getkeyboardstate in user32"

Any (further) suggestions?
 
J

Jim Rech

This works for me in Excel 97:


Declare Sub GetKeyboardState Lib "USER32" (lpKeystate As Any)
Declare Sub keybd_event Lib "USER32" _
(ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2

Sub NTKeyNumlockOn()
Dim lpbKeyState(0 To 255) As Byte
GetKeyboardState lpbKeyState(0)
If lpbKeyState(vbKeyNumlock) = 0 Then
keybd_event vbKeyNumlock, 0, KEYEVENTF_EXTENDEDKEY Or 0, 0
keybd_event vbKeyNumlock, 0, KEYEVENTF_EXTENDEDKEY Or
KEYEVENTF_KEYUP, 0
End If
End Sub

--
Jim
|
| Unfortunately I cant get his solution to work, I keep getting
|
| "Can't find DLL entry point getkeyboardstate in user32"
|
| Any (further) suggestions?
 
P

Peter T

Try simply -

Declare Function SetKeyboardState _
Lib "User32" (kbArray As Byte) As Long

Sub NumLocker()

Dim KeyState(0 To 255) As Byte
KeyState(&H90) = 1 ' 1 NumLock on, 0 for off
SetKeyboardState KeyState(0)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top