docs(dotnet): Keyboard examples (#6539)

This commit is contained in:
Anže Vodovnik 2021-05-13 11:15:27 +02:00 committed by GitHub
parent 17e9dd95f7
commit fce904fa4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,6 +54,20 @@ page.keyboard.press("Backspace")
# result text will end up saying "Hello!"
```
```csharp
await page.Keyboard.TypeAsync("Hello World!");
await page.Keyboard.PressAsync("ArrowLeft");
await page.Keyboard.DownAsync("Shift");
for (int i = 0; i < " World".Length; i++)
await page.Keyboard.PressAsync("ArrowLeft");
await page.Keyboard.UpAsync("Shift");
await page.Keyboard.PressAsync("Backspace");
// Result text will end up saying "Hello!"
```
An example of pressing uppercase `A`
```js
@ -80,6 +94,12 @@ page.keyboard.press("Shift+KeyA")
page.keyboard.press("Shift+A")
```
```csharp
await page.Keyboard.PressAsync("Shift+KeyA");
// or
await page.Keyboard.PressAsync("Shift+A");
```
An example to trigger select-all with the keyboard
```js
@ -110,6 +130,13 @@ page.keyboard.press("Control+A")
page.keyboard.press("Meta+A")
```
```csharp
// on Windows and Linux
await page.Keyboard.PressAsync("Control+A");
// on macOS
await page.Keyboard.PressAsync("Meta+A");
```
## async method: Keyboard.down
Dispatches a `keydown` event.
@ -165,6 +192,10 @@ await page.keyboard.insert_text("嗨")
page.keyboard.insert_text("嗨")
```
```csharp
await page.Keyboard.PressAsync("嗨");
```
:::note
Modifier keys DO NOT effect `keyboard.insertText`. Holding down `Shift` will not type the text in upper case.
:::
@ -242,6 +273,17 @@ page.screenshot(path="o.png")
browser.close()
```
```csharp
await page.GoToAsync("https://keycode.info");
await page.Keyboard.PressAsync("A");
await page.ScreenshotAsync("A.png");
await page.Keyboard.PressAsync("ArrowLeft");
await page.ScreenshotAsync("ArrowLeft.png");
await page.Keyboard.PressAsync("Shift+O");
await page.ScreenshotAsync("O.png");
await browser.CloseAsync();
```
Shortcut for [`method: Keyboard.down`] and [`method: Keyboard.up`].
### param: Keyboard.press.key
@ -282,6 +324,11 @@ page.keyboard.type("Hello") # types instantly
page.keyboard.type("World", delay=100) # types slower, like a user
```
```csharp
await page.Keyboard.TypeAsync("Hello"); // types instantly
await page.Keyboard.TypeAsync("World"); // types slower, like a user
```
:::note
Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
:::