Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(dotnet): Keyboard examples #6539

Merged
merged 2 commits into from May 13, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions docs/src/api/class-keyboard.md
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.Press("Meta+A");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Thanks for spotting it.

avodovnik marked this conversation as resolved.
Show resolved Hide resolved
```

## async method: Keyboard.down

Dispatches a `keydown` event.
Expand Down Expand Up @@ -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.
:::
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
:::
Expand Down