Skip to content

Commit 4af53ce

Browse files
avodovnikpavelfeldman
authored andcommitted
docs(dotnet): Keyboard examples (#6539)
1 parent 9b69512 commit 4af53ce

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/src/api/class-keyboard.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5771
An example of pressing uppercase `A`
5872

5973
```js
@@ -80,6 +94,12 @@ page.keyboard.press("Shift+KeyA")
8094
page.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+
83103
An example to trigger select-all with the keyboard
84104

85105
```js
@@ -110,6 +130,13 @@ page.keyboard.press("Control+A")
110130
page.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

115142
Dispatches a `keydown` event.
@@ -165,6 +192,10 @@ await page.keyboard.insert_text("嗨")
165192
page.keyboard.insert_text("")
166193
```
167194

195+
```csharp
196+
await page.Keyboard.PressAsync("");
197+
```
198+
168199
:::note
169200
Modifier 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")
242273
browser.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+
245287
Shortcut for [`method: Keyboard.down`] and [`method: Keyboard.up`].
246288

247289
### param: Keyboard.press.key
@@ -282,6 +324,11 @@ page.keyboard.type("Hello") # types instantly
282324
page.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
286333
Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
287334
:::

0 commit comments

Comments
 (0)