mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	docs(dotnet): Keyboard examples (#6539)
This commit is contained in:
		
							parent
							
								
									17e9dd95f7
								
							
						
					
					
						commit
						fce904fa4c
					
				@ -54,6 +54,20 @@ page.keyboard.press("Backspace")
 | 
				
			|||||||
# result text will end up saying "Hello!"
 | 
					# 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`
 | 
					An example of pressing uppercase `A`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```js
 | 
					```js
 | 
				
			||||||
@ -80,6 +94,12 @@ page.keyboard.press("Shift+KeyA")
 | 
				
			|||||||
page.keyboard.press("Shift+A")
 | 
					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
 | 
					An example to trigger select-all with the keyboard
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```js
 | 
					```js
 | 
				
			||||||
@ -110,6 +130,13 @@ page.keyboard.press("Control+A")
 | 
				
			|||||||
page.keyboard.press("Meta+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
 | 
					## async method: Keyboard.down
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Dispatches a `keydown` event.
 | 
					Dispatches a `keydown` event.
 | 
				
			||||||
@ -165,6 +192,10 @@ await page.keyboard.insert_text("嗨")
 | 
				
			|||||||
page.keyboard.insert_text("嗨")
 | 
					page.keyboard.insert_text("嗨")
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```csharp
 | 
				
			||||||
 | 
					await page.Keyboard.PressAsync("嗨");
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:::note
 | 
					:::note
 | 
				
			||||||
Modifier keys DO NOT effect `keyboard.insertText`. Holding down `Shift` will not type the text in upper case.
 | 
					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()
 | 
					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`].
 | 
					Shortcut for [`method: Keyboard.down`] and [`method: Keyboard.up`].
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### param: Keyboard.press.key
 | 
					### 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
 | 
					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
 | 
					:::note
 | 
				
			||||||
Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
 | 
					Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
 | 
				
			||||||
:::
 | 
					:::
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user