SendKeys "{CAPSLOCK}" Toggles CAPS LOCK Key State

Last reviewed: July 29, 1997
Article ID: Q125947
The information in this article applies to:
  • Microsoft Visual Basic Programming System, Applications Edition, 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

REFERENCES

For more information about the SendKeys Statement or the SendKeys Method, choose the Search button in the Visual Basic Reference and type:

   SendKeys
Keywords          : kbcode kbprg
Version           : 1.00
Platform          : WINDOWS


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.