SendKeys Statement Doesn't Affect NUM LOCK Key State

Last reviewed: July 29, 1997
Article ID: Q133327
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 with the {NUMLOCK} key code in a Visual Basic, Applications Edition, procedure to send the NUM LOCK key, the NUM LOCK key state is not affected.

Note that when you use the SendKeys statement to send the NUM LOCK key, while Microsoft Excel or Microsoft Project is the active application, the word NUM on the status bar is toggled (either appears or disappears). However, the NUM LOCK light on your keyboard (which indicates the state of the NUM LOCK key) does not change.

The expected behavior is for the SendKeys command to turn NUM LOCK off at the start of the SendKeys command, the {NUMLOCK} key code in the SendKeys command to toggle the NUM LOCK state, and the NUM LOCK state to be restored to its original state after the SendKeys command is finished.

WORKAROUND

In Microsoft Excel, you can use the SendKeys method to work around this behavior, as in the following example:

   Sub Test()
      Application.SendKeys "{NUMLOCK}This is a test of the NUM LOCK key"
   End Sub

When you run this procedure while a worksheet is active in Microsoft Excel, NUM LOCK is turned off (if it is currently on), the NUM LOCK state in the application is toggled (although the NUM LOCK light does not change), the text is entered on the worksheet, and NUM LOCK is returned to its initial state.

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 NUM LOCK is on, the numbers and mathematical symbols that appear on the numeric keypad will be entered into the worksheet when you press the keys. When NUM LOCK is off, the keypad is mapped to arrows (2,4,6,8) arithmetic functions (=,/,*,-,+,), and the function keys HOME (7), END (1), PgUp (9) , and PgDn (3).

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.