Bewerken

Share via


SendKeys.SendWait(String) Method

Definition

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

public:
 static void SendWait(System::String ^ keys);
public static void SendWait (string keys);
static member SendWait : string -> unit
Public Shared Sub SendWait (keys As String)

Parameters

keys
String

The string of keystrokes to send.

Remarks

Use SendWait 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 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 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 SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the SendKeys class may behave differently on different operating systems. Additionally, when the SendKeys class uses the new implementation, the SendWait 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 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 SendKeys class to use the previous implementation, use the value "JournalHook" instead.

Applies to