SendKeys Statement Doesn't Affect NUM LOCK Key State

ID: Q133327


The information in this article applies to:
  • Microsoft Visual Basic programming system, Applications Edition
  • 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

Additional query words:

Keywords :
Version : :; WINDOWS:4.0,5.0,5.0c
Platform : WINDOWS
Issue type :


Last Reviewed: October 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.