System.Windows.Forms.SendKeys.SendWait Method

Sends the given keys to the active application, and then waits for the messages to be processed.

Syntax

public static void SendWait (string keys)

Parameters

keys
The string of keystrokes to send.

Remarks

Use SendKeys.SendWait(string) to send keystrokes or combinations of keystrokes to the active application and wait for the keystroke messages to be processed. You can use this method to send keystrokes to an application and wait for any processes that are started by the keystrokes to be completed. This can be important if the other application must finish before your application can continue.

Note:

Because there is no managed method to activate another application, you can either use this class within the current application or use native Windows methods, such as FindWindow and SetForegroundWindow, to force focus on other applications.

Note:

The System.Windows.Forms.SendKeys class has been updated for the .NET Framework 3.0 to enable its use in applications that run on Windows Vista. The enhanced security of Windows Vista (known as User Account Control or UAC) prevents the previous implementation from working as expected.

The System.Windows.Forms.SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds. The System.Windows.Forms.SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the System.Windows.Forms.SendKeys class may behave differently on different operating systems. Additionally, when the System.Windows.Forms.SendKeys class uses the new implementation, the SendKeys.SendWait(string) method will not wait for messages to be processed when they are sent to another process.

If your application relies on consistent behavior regardless of the operating system, you can force the System.Windows.Forms.SendKeys class to use the new implementation by adding the following application setting to your app.config file.

<appSettings>

<add key="SendKeys" value="SendInput"/>

</appSettings>

To force the System.Windows.Forms.SendKeys class to use the previous implementation, use the value "JournalHook" instead.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0