SendInput
 




Description

For all the complaints that Vista broke this, and Vista broke that, Vista really didn't break Classic VB all that badly. That said, one VB statement did truly get hammered. This sample provides a drop-in replacement for the standard SendKeys statement, and should work just fine in all the environments (VB5, VB6 IDE, VBA other than Office 2007) where this broke. I believe it's written to exactly emulate SendKeys, without exception <g>.

Well, all but one "feature" of SendKeys, at any rate -- the Wait parameter. Can anyone tell me what that's all about? My routine accepts, but ignores, this parameter.

As you'll see, using MySendKeys is absolutely identical to native SendKeys:

Color-coded with vbMarkUp - try it today!
Private Sub Command1_Click()
   Text1.SetFocus
   Call MySendKeys(Text2.Text)
   DoEvents
   Command1.SetFocus
End Sub

Private Sub Command2_Click()
   Text1.SetFocus
   Call VBA.SendKeys(Text2.Text)
   DoEvents
   Command2.SetFocus
End Sub

Private Sub Form_Load()
   Text2.Text = "{home}+{end}Testing123+(123)"
End Sub

One change you may want to think about making would be to rename the MySendKeys subroutine to SendKeys. That will avoid having to change anything else in your code, as it will override the SendKeys statement in the VBA object library from that point onward. In order to use the original SendKeys, you'll then have to prefix it with "VBA." as shown above.

Note on Conditional Compilation

The MSendInput.bas module contains a conditional compilation constant that determines whether the native language implementation of Split() is compiled in or not. If this constant is defined as False, as it is in the download, the module may be used in VB5 as well as VB6 and VBA.

Published

This sample, or the one from which it originally derived, was published (or at least peripherally mentioned) in the following article(s):

APIs Usage

This sample uses the following API calls:

Module Library Function
MSendInput.bas user32
SendInput
VkKeyScan

Download

Download SendInput.zip   Please, enjoy and learn from this sample. Include its code within your own projects, if you wish. But, in order to insure only the most recent code is available to all, I ask that you don't share the sample by any form of mass distribution.

Download SendInput.zip, 15Kb, Last Updated: Tuesday, 27 November 2007

See Also