ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   NUM LOCK status (https://www.excelbanter.com/excel-programming/338022-num-lock-status.html)

Black1

NUM LOCK status
 
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

Peter T

NUM LOCK status
 
See Dave Peterson's post in this thread

http://tinyurl.com/cuocs

Regards,
Peter T


"Black1" wrote in message
...
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




Black1

NUM LOCK status
 

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

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

Any (further) suggestions?

Jim Rech

NUM LOCK status
 
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
"Black1" wrote in message
...
|
| Unfortunately I cant get his solution to work, I keep getting
|
| "Can't find DLL entry point getkeyboardstate in user32"
|
| Any (further) suggestions?



Peter T

NUM LOCK status
 
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


"Black1" wrote in message
...

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

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

Any (further) suggestions?





All times are GMT +1. The time now is 12:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com