-
Hi Kenneth, I know it's an old thread, I thought I'd mention that your routine works fine, but i found an anomaly. I managed to get into a situation where turning the numlocks on occurred twice in quick succession, resulting in the numlocks remaining off, emulated here:
'Turn Numlock on
If Not (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
'More code here in the full application,
If Not (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
I guessed it was to do with timing, so the 2nd block toggled numlocks off again, you can actually see the LED flash on and off.
Single stepping through worked perfectly, so as an experiment I modified the above to
'Turn Numlock on
If Not (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
'More code here in the full application,
Call WaitABit (0.5) 'wait for 500mSec
If Not (GetKeyState(vbKeyNumlock) = 1) Then
keybd_event VK_NUMLOCK, 1, 0, 0
keybd_event VK_NUMLOCK, 1, KEYEVENTF_KEYUP, 0
End If
The delay fixed the problem, although the proper fix was to remove the extraneous block of code.
Thanks for posting your solution, it's much more reliable than using Sendkeys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules