SendKeys "{CAPSLOCK}" Toggles CAPS LOCK Key StateLast reviewed: July 29, 1997Article ID: Q125947 |
The information in this article applies to:
SYMPTOMSWhen 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.
WORKAROUNDTo 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 SubWhen you run the above procedure, if CAPS LOCK is off, the following text is sent to the active window:
abcDEFNote 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.
STATUSMicrosoft 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 INFORMATIONWhen 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 REFERENCESFor 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 |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |