Microsoft KB Archive/125947

{|
 * width="100%"|

SendKeys "{CAPSLOCK}" Toggles CAPS LOCK Key State

 * }

Q125947

-

The information in this article applies to:


 * Microsoft Visual Basic for Applications version 1.0
 * Microsoft Excel for Windows, versions 5.0, 5.0c
 * Microsoft Project for Windows, version 4.0

-

SYMPTOMS
When you use the SendKeys statement in a Visual Basic, Applications Edition, procedure to send the CAPS LOCK keystroke, the CAPS LOCK key is toggled. For example, if the CAPS LOCK key is on, the SendKeys statement toggles the CAPS LOCK key off, and vice versa. Because you cannot test for the state of the CAPS LOCK key, you cannot selectively send uppercase or lowercase characters to a document or application.

WORKAROUND
To work around this behavior in Microsoft Excel, you can use the SendKeys method instead of the SendKeys statement, to send the CAPS LOCK keystroke as in the following example:

  Sub Test Application.SendKeys "{CAPSLOCK}ABCdef" End Sub When you run the above procedure, if CAPS LOCK is off, the following text is sent to the active window:

"abcDEF" Note that the result does not depend on the current state of the CAPS LOCK key.

Note also that you cannot use the SendKeys method in Microsoft Project.

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION
When you use the SendKeys statement with the {CAPSLOCK} code, to send the CAPS LOCK keystroke, this command toggles the state of CAPS LOCK, so that the result of the command depends on the state of CAPS LOCK. When the procedure is finished, the CAPS LOCK key is left in its toggled state. If CAPS LOCK is on before you run the procedure, it is off after you run the procedure. The following table shows the different results after running the command Application.SendKeys "{CAPSLOCK}ABCdef":

Initial Caps | SendKeys | Post      | SendKeys | Post Caps Lock State  | Statement | Cap State | Method   | Lock State ---  Caps On    |  ABCdef   | Caps Off  |  abcDEF  |  Caps On   Caps Off   |  abcDEF   | Caps On   |  abcDEF  |  Caps Off