Previous | Index | Next 

[PRB] The system hangs when using SendKeys to simulate key presses in an external application

VB6’s SendKeys command is translated to a call to the My.Computer.Keyboard.SendKeys method. In some circumstances the migrated VB.NET code freezes the system and you can regain control only by pressing Ctrl-Alt-Del to run the Task Manager.

We have observed this behavior only in some specific circumstances, most notably when all the following conditions are met:

  1. the SendKeys command is followed by a Shell command that runs an external application,
  2. the wait argument is omitted in the original SendKeys command,
  3. the WaitForSingleObject API method is used to detect when the external application gets the input focus.

The easiest workaround for this problem – which is caused by the different implementation of SendKeys in the two languages – is to explicitly add a second argument to the original SendKeys statement:

    SendKeys keylist, True

This fix doesn’t seem to affect negatively the behavior of the VB6 application in the abovementioned circumstances.


Previous | Index | Next