SendKeys "{CAPSLOCK}" Toggles CAPS LOCK Key State |
Q125947
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.
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:
abcDEFNote that the result does not depend on the current state of the CAPS LOCK key.
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.
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
For more information about the SendKeys Statement or the SendKeys Method, choose the Search button in the Visual Basic Reference and type:
SendKeys
Additional query words:
Keywords :
Issue type :
Technology : kbExcelSearch kbZNotKeyword6 kbExcel500 kbProjectSearch kbVBASearch kbZNotKeyword3 kbExcel500c kbProject400 kbVBA100
|
Last Reviewed: January 17, 2001 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |