NumLock Key May Turn Off Unexpectedly
CAUSE:
Executing at least two SendKeys statements in a row results in turning off the NumLock key. This problem may also affect the CapsLock and ScrollLock keys.
This problem deals with a nesting of capturing the keyboard state. The first SendKeys statement takes a snapshot of the keyboard state and turns off all toggles. The second SendKeys statement executes before the first one played out all keys and restored the keyboard state. So, the keyboard state is recorded again by the second SendKeys, this time with all toggles still off. Eventually, the keyboard state is restored to the later state (toggles off).
SOLUTION:
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
WORKAROUND:
There seem to be two options for this.
(1) Use the Windows API. There is a Tek-Tip Thread on this. Look up "Numlock"
(2) Apply a DOevents between your SendKeys statements, if applicable. Example:
Private Sub Command1_Click()
SendKeys "a"
DoEvents
SendKeys "b"
End Sub
NOTE: You should restart Visual Basic before trying the DoEvents
solution. Otherwise, the keyboard state may be set incorrectly,
Most of the above information was quoted from the Microsoft Knowledge Base.
Gary
gwinn7
CAUSE:
Executing at least two SendKeys statements in a row results in turning off the NumLock key. This problem may also affect the CapsLock and ScrollLock keys.
This problem deals with a nesting of capturing the keyboard state. The first SendKeys statement takes a snapshot of the keyboard state and turns off all toggles. The second SendKeys statement executes before the first one played out all keys and restored the keyboard state. So, the keyboard state is recorded again by the second SendKeys, this time with all toggles still off. Eventually, the keyboard state is restored to the later state (toggles off).
SOLUTION:
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
WORKAROUND:
There seem to be two options for this.
(1) Use the Windows API. There is a Tek-Tip Thread on this. Look up "Numlock"
(2) Apply a DOevents between your SendKeys statements, if applicable. Example:
Private Sub Command1_Click()
SendKeys "a"
DoEvents
SendKeys "b"
End Sub
NOTE: You should restart Visual Basic before trying the DoEvents
solution. Otherwise, the keyboard state may be set incorrectly,
Most of the above information was quoted from the Microsoft Knowledge Base.
Gary
gwinn7