@@ -54,6 +54,20 @@ page.keyboard.press("Backspace")
5454# result text will end up saying "Hello!"
5555```
5656
57+ ``` csharp
58+ await page .Keyboard .TypeAsync (" Hello World!" );
59+ await page .Keyboard .PressAsync (" ArrowLeft" );
60+
61+ await page .Keyboard .DownAsync (" Shift" );
62+ for (int i = 0 ; i < " World" .Length ; i ++ )
63+ await page .Keyboard .PressAsync (" ArrowLeft" );
64+
65+ await page .Keyboard .UpAsync (" Shift" );
66+
67+ await page .Keyboard .PressAsync (" Backspace" );
68+ // Result text will end up saying "Hello!"
69+ ```
70+
5771An example of pressing uppercase ` A `
5872
5973``` js
@@ -80,6 +94,12 @@ page.keyboard.press("Shift+KeyA")
8094page.keyboard.press(" Shift+A" )
8195```
8296
97+ ``` csharp
98+ await page .Keyboard .PressAsync (" Shift+KeyA" );
99+ // or
100+ await page .Keyboard .PressAsync (" Shift+A" );
101+ ```
102+
83103An example to trigger select-all with the keyboard
84104
85105``` js
@@ -110,6 +130,13 @@ page.keyboard.press("Control+A")
110130page.keyboard.press(" Meta+A" )
111131```
112132
133+ ``` csharp
134+ // on Windows and Linux
135+ await page .Keyboard .PressAsync (" Control+A" );
136+ // on macOS
137+ await page .Keyboard .PressAsync (" Meta+A" );
138+ ```
139+
113140## async method: Keyboard.down
114141
115142Dispatches a ` keydown ` event.
@@ -165,6 +192,10 @@ await page.keyboard.insert_text("嗨")
165192page.keyboard.insert_text(" 嗨" )
166193```
167194
195+ ``` csharp
196+ await page .Keyboard .PressAsync (" 嗨" );
197+ ```
198+
168199::: note
169200Modifier keys DO NOT effect ` keyboard.insertText ` . Holding down ` Shift ` will not type the text in upper case.
170201:::
@@ -242,6 +273,17 @@ page.screenshot(path="o.png")
242273browser. close()
243274```
244275
276+ ```csharp
277+ await page. GoToAsync (" https://keycode.info" );
278+ await page. Keyboard . PressAsync(" A" );
279+ await page. ScreenshotAsync (" A.png" );
280+ await page. Keyboard . PressAsync(" ArrowLeft" );
281+ await page. ScreenshotAsync (" ArrowLeft.png" );
282+ await page. Keyboard . PressAsync(" Shift+O" );
283+ await page. ScreenshotAsync (" O.png" );
284+ await browser. CloseAsync ();
285+ ```
286+
245287Shortcut for [`method: Keyboard . down`] and [`method: Keyboard . up`].
246288
247289### param: Keyboard . press. key
@@ -282,6 +324,11 @@ page.keyboard.type("Hello") # types instantly
282324page. keyboard. type(" World" , delay= 100 ) # types slower, like a user
283325```
284326
327+ ```csharp
328+ await page. Keyboard . TypeAsync(" Hello" ); // types instantly
329+ await page. Keyboard . TypeAsync(" World" ); // types slower, like a user
330+ ```
331+
285332::: note
286333Modifier keys DO NOT effect `keyboard. type`. Holding down `Shift ` will not type the text in upper case .
287334:::
0 commit comments