BUG: Multiple SendKeys Statement Turns Off NumLock Key (179987)
The information in this article applies to:
- Microsoft Visual Basic for Applications 5.0
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
This article was previously published under Q179987 SYMPTOMS
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.
CAUSE
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).
RESOLUTION
To work around this problem, do one of the following:
- Send all the characters in a single SendKeys statement.
-or-
- Execute a DoEvents function between each SendKeys statement. However,
depending on the complexity of the key strokes, this may not work in
all cases.
-or-
- Determine the setting of the NumLock key prior to using SendKeys. Then,
turn off the NumLock before using SendKeys. After using SendKeys, reset
the NumLock to its previous setting. This is accomplished using the
GetKeyboardState, keybd_event and SetKeyboardState API functions. See
the REFERENCES section below for more information.
-or-
- Use API functions instead of SendKeys. See the REFERENCES section below
for more information,
STATUS
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.
REFERENCES
"Visual Basic 5.0 Programmer's Guide to the Win32 API," by Dan Appleman
Chapter 6: Hardware and System Functions
For additional information, see the following article in the Microsoft
Knowledge Base:
177674 HOWTO: Toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK Keys
Modification Type: | Major | Last Reviewed: | 6/29/2004 |
---|
Keywords: | kbbug kbpending kbProgramming KB179987 |
---|
|