-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
SendKeys.xml
373 lines (333 loc) · 22.2 KB
/
SendKeys.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<Type Name="SendKeys" FullName="System.Windows.Forms.SendKeys">
<TypeSignature Language="C#" Value="public class SendKeys" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi SendKeys extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Windows.Forms.SendKeys" />
<TypeSignature Language="VB.NET" Value="Public Class SendKeys" />
<TypeSignature Language="F#" Value="type SendKeys = class" />
<TypeSignature Language="C++ CLI" Value="public ref class SendKeys" />
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="windowsdesktop-8.0;windowsdesktop-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(0)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="windowsdesktop-8.0;windowsdesktop-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(1)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Provides methods for sending keystrokes to an application.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use <xref:System.Windows.Forms.SendKeys> to send keystrokes and keystroke combinations to the active application. This class cannot be instantiated. To send a keystroke to a class and immediately continue with the flow of your program, use <xref:System.Windows.Forms.SendKeys.Send%2A>. To wait for any processes started by the keystroke, use <xref:System.Windows.Forms.SendKeys.SendWait%2A>.
Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, pass in the string "A" to the method. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, specify the parameter as "ABC".
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to <xref:System.Windows.Forms.SendKeys>. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use "{+}". To specify brace characters, use "{{}" and "{}}". Brackets ([ ]) have no special meaning to <xref:System.Windows.Forms.SendKeys>, but you must enclose them in braces. In other applications, brackets do have a special meaning that might be significant when dynamic data exchange (DDE) occurs.
> [!CAUTION]
> If your application is intended for international use with a variety of keyboards, the use of <xref:System.Windows.Forms.SendKeys.Send%2A> could yield unpredictable results and should be avoided.
To specify characters that aren't displayed when you press a key, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes in the following table.
|Key|Code|
|---------|----------|
|BACKSPACE|{BACKSPACE}, {BS}, or {BKSP}|
|BREAK|{BREAK}|
|CAPS LOCK|{CAPSLOCK}|
|DEL or DELETE|{DELETE} or {DEL}|
|DOWN ARROW|{DOWN}|
|END|{END}|
|ENTER|{ENTER} or ~|
|ESC|{ESC}|
|HELP|{HELP}|
|HOME|{HOME}|
|INS or INSERT|{INSERT} or {INS}|
|LEFT ARROW|{LEFT}|
|NUM LOCK|{NUMLOCK}|
|PAGE DOWN|{PGDN}|
|PAGE UP|{PGUP}|
|PRINT SCREEN|{PRTSC} (reserved for future use)|
|RIGHT ARROW|{RIGHT}|
|SCROLL LOCK|{SCROLLLOCK}|
|TAB|{TAB}|
|UP ARROW|{UP}|
|F1|{F1}|
|F2|{F2}|
|F3|{F3}|
|F4|{F4}|
|F5|{F5}|
|F6|{F6}|
|F7|{F7}|
|F8|{F8}|
|F9|{F9}|
|F10|{F10}|
|F11|{F11}|
|F12|{F12}|
|F13|{F13}|
|F14|{F14}|
|F15|{F15}|
|F16|{F16}|
|Keypad add|{ADD}|
|Keypad subtract|{SUBTRACT}|
|Keypad multiply|{MULTIPLY}|
|Keypad divide|{DIVIDE}|
To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes.
|Key|Code|
|---------|----------|
|SHIFT|+|
|CTRL|^|
|ALT|%|
To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".
To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.
> [!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 <xref: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 <xref: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 <xref:System.Windows.Forms.SendKeys> class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the <xref:System.Windows.Forms.SendKeys> class may behave differently on different operating systems. Additionally, when the <xref:System.Windows.Forms.SendKeys> class uses the new implementation, the <xref:System.Windows.Forms.SendKeys.SendWait%2A> 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 <xref: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 <xref:System.Windows.Forms.SendKeys> class to use the previous implementation, use the value `"JournalHook"` instead.
## Examples
The following code example demonstrates how to use the <xref:System.Windows.Forms.SendKeys.Send%2A> method. To run the example, paste the following code in a form called Form1 containing a button called Button1. Ensure the click events are associated with their event-handling methods in this example. The button control's <xref:System.Windows.Forms.Control.TabIndex%2A> property should be set to 0. When the example is running, double-click the form to trigger the button's click event.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.SendKeys/CPP/form1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/SendKeys/Overview/form1.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.SendKeys/VB/form1.vb" id="Snippet1":::
]]></format>
</remarks>
</Docs>
<Members>
<Member MemberName="Flush">
<MemberSignature Language="C#" Value="public static void Flush ();" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void Flush() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Forms.SendKeys.Flush" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub Flush ()" />
<MemberSignature Language="F#" Value="static member Flush : unit -> unit" Usage="System.Windows.Forms.SendKeys.Flush " />
<MemberSignature Language="C++ CLI" Value="public:
 static void Flush();" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Processes all the Windows messages currently in the message queue.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use <xref:System.Windows.Forms.SendKeys.Flush%2A> to wait for the application to process keystrokes and other operating system messages that are in the message queue. This is equivalent to calling <xref:System.Windows.Forms.Application.DoEvents%2A?displayProperty=nameWithType> until there are no more keys to process.
> [!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.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Send">
<MemberSignature Language="C#" Value="public static void Send (string keys);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void Send(string keys) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Forms.SendKeys.Send(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub Send (keys As String)" />
<MemberSignature Language="F#" Value="static member Send : string -> unit" Usage="System.Windows.Forms.SendKeys.Send keys" />
<MemberSignature Language="C++ CLI" Value="public:
 static void Send(System::String ^ keys);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="keys" Type="System.String" />
</Parameters>
<Docs>
<param name="keys">The string of keystrokes to send.</param>
<summary>Sends keystrokes to the active application.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, pass in the string "A" to the method. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, specify the parameter as "ABC".
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to <xref:System.Windows.Forms.SendKeys>. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use "{+}". To specify brace characters, use "{{}" and "{}}". Brackets ([ ]) have no special meaning to <xref:System.Windows.Forms.SendKeys>, but you must enclose them in braces. In other applications, brackets do have a special meaning that might be significant when dynamic data exchange (DDE) occurs.
> [!CAUTION]
> If your application is intended for international use with a variety of keyboards, the use of <xref:System.Windows.Forms.SendKeys.Send%2A> could yield unpredictable results and should be avoided.
To specify characters that aren't displayed when you press a key, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes in the following table.
|Key|Code|
|---------|----------|
|BACKSPACE|{BACKSPACE}, {BS}, or {BKSP}|
|BREAK|{BREAK}|
|CAPS LOCK|{CAPSLOCK}|
|DEL or DELETE|{DELETE} or {DEL}|
|DOWN ARROW|{DOWN}|
|END|{END}|
|ENTER|{ENTER}or ~|
|ESC|{ESC}|
|HELP|{HELP}|
|HOME|{HOME}|
|INS or INSERT|{INSERT} or {INS}|
|LEFT ARROW|{LEFT}|
|NUM LOCK|{NUMLOCK}|
|PAGE DOWN|{PGDN}|
|PAGE UP|{PGUP}|
|PRINT SCREEN|{PRTSC} (reserved for future use)|
|RIGHT ARROW|{RIGHT}|
|SCROLL LOCK|{SCROLLLOCK}|
|TAB|{TAB}|
|UP ARROW|{UP}|
|F1|{F1}|
|F2|{F2}|
|F3|{F3}|
|F4|{F4}|
|F5|{F5}|
|F6|{F6}|
|F7|{F7}|
|F8|{F8}|
|F9|{F9}|
|F10|{F10}|
|F11|{F11}|
|F12|{F12}|
|F13|{F13}|
|F14|{F14}|
|F15|{F15}|
|F16|{F16}|
|Keypad add|{ADD}|
|Keypad subtract|{SUBTRACT}|
|Keypad multiply|{MULTIPLY}|
|Keypad divide|{DIVIDE}|
To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes.
|Key|Code|
|---------|----------|
|SHIFT|+|
|CTRL|^|
|ALT|%|
To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".
To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.
> [!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 <xref: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 <xref: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 <xref:System.Windows.Forms.SendKeys> class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the <xref:System.Windows.Forms.SendKeys> class may behave differently on different operating systems. Additionally, when the <xref:System.Windows.Forms.SendKeys> class uses the new implementation, the <xref:System.Windows.Forms.SendKeys.SendWait%2A> 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 <xref: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 <xref:System.Windows.Forms.SendKeys> class to use the previous implementation, use the value `"JournalHook"` instead.
## Examples
The following code example demonstrates how to use the <xref:System.Windows.Forms.SendKeys.Send%2A> method.To run the example, paste the following code in a form called Form1 containing a button called Button1. Ensure the click events are associated with their event-handling methods in this example. The button control's <xref:System.Windows.Forms.Control.TabIndex%2A> property should be set to 0. When the example is running, double-click the form to trigger the button's click event.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.SendKeys/CPP/form1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Windows.Forms/SendKeys/Overview/form1.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.SendKeys/VB/form1.vb" id="Snippet1":::
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">There is not an active application to send keystrokes to.</exception>
<exception cref="T:System.ArgumentException">
<paramref name="keys" /> does not represent valid keystrokes.</exception>
</Docs>
</Member>
<Member MemberName="SendWait">
<MemberSignature Language="C#" Value="public static void SendWait (string keys);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void SendWait(string keys) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Forms.SendKeys.SendWait(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Shared Sub SendWait (keys As String)" />
<MemberSignature Language="F#" Value="static member SendWait : string -> unit" Usage="System.Windows.Forms.SendKeys.SendWait keys" />
<MemberSignature Language="C++ CLI" Value="public:
 static void SendWait(System::String ^ keys);" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Windows.Forms</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="keys" Type="System.String" />
</Parameters>
<Docs>
<param name="keys">The string of keystrokes to send.</param>
<summary>Sends the given keys to the active application, and then waits for the messages to be processed.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Use <xref:System.Windows.Forms.SendKeys.SendWait%2A> 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 <xref: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 <xref: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 <xref:System.Windows.Forms.SendKeys> class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the <xref:System.Windows.Forms.SendKeys> class may behave differently on different operating systems. Additionally, when the <xref:System.Windows.Forms.SendKeys> class uses the new implementation, the <xref:System.Windows.Forms.SendKeys.SendWait%2A> 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 <xref: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 <xref:System.Windows.Forms.SendKeys> class to use the previous implementation, use the value `"JournalHook"` instead.
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>