PRB: SendKeys Does Not Work with NumLock or Caplock
Article ID: 192273
Article Last Modified on 5/12/2003
APPLIES TO
- Microsoft Visual Basic 5.0 Learning Edition
- Microsoft Visual Basic 6.0 Learning Edition
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft Visual Basic 4.0 Standard Edition
This article was previously published under Q192273
SYMPTOMS
Using SendKeys to change the state of {CAPSLOCK} or {NUMLOCK} is not
effective.
CAUSE
Toggling {CAPSLOCK} or {NUMLOCK} with the SendKeys statement is only in
effect for the continuous subsequent keys sent by SendKeys. The state of
{CAPSLOCK} or {NUMLOCK} is reset when Visual Basic yields to other
processes. For example, this occurs when the SendKeys statement's Wait
parameter is set to "True", or when a DoEvents statement is executed.
RESOLUTION
Use SendKeys to toggle {CAPSLOCK} or {NUMLOCK} only when sending a series
of keys continuously in a single or multiple number of SendKeys statements.
To toggle the {CAPSLOCK} or {NUMLOCK} permanently:
- Use the KeyState control that comes with Visual Basic 4.0.
- or -
- Use the Win32 API. See the article in the References section for
details.
STATUS
This behavior is by design.
REFERENCES
For additional information, please see the following article in the
Microsoft Knowledge Base:
177674
: HOWTO: Toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK Keys
Keywords: kbprb kbcode KB192273