204 lines
6.8 KiB
Python
204 lines
6.8 KiB
Python
"""
|
|
This type stub file was generated by pyright.
|
|
"""
|
|
|
|
from typing import Any, Dict, TYPE_CHECKING
|
|
from pyppeteer.connection import CDPSession
|
|
|
|
"""Keyboard and Mouse module."""
|
|
if TYPE_CHECKING:
|
|
...
|
|
class Keyboard:
|
|
"""Keyboard class provides as api for managing a virtual keyboard.
|
|
|
|
The high level api is :meth:`type`, which takes raw characters and
|
|
generate proper keydown, keypress/input, and keyup events on your page.
|
|
|
|
For finer control, you can use :meth:`down`, :meth:`up`, and
|
|
:meth:`sendCharacter` to manually fire events as if they were generated
|
|
from a real keyboard.
|
|
|
|
An example of holding down ``Shift`` in order to select and delete some
|
|
text:
|
|
|
|
.. code::
|
|
|
|
await page.keyboard.type('Hello, World!')
|
|
await page.keyboard.press('ArrowLeft')
|
|
|
|
await page.keyboard.down('Shift')
|
|
for i in ' World':
|
|
await page.keyboard.press('ArrowLeft')
|
|
await page.keyboard.up('Shift')
|
|
|
|
await page.keyboard.press('Backspace')
|
|
# Result text will end up saying 'Hello!'.
|
|
|
|
An example of pressing ``A``:
|
|
|
|
.. code::
|
|
|
|
await page.keyboard.down('Shift')
|
|
await page.keyboard.press('KeyA')
|
|
await page.keyboard.up('Shift')
|
|
"""
|
|
def __init__(self, client: CDPSession) -> None:
|
|
...
|
|
|
|
async def down(self, key: str, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
|
"""Dispatch a ``keydown`` event with ``key``.
|
|
|
|
If ``key`` is a single character and no modifier keys besides ``Shift``
|
|
are being held down, and a ``keypress``/``input`` event will also
|
|
generated. The ``text`` option can be specified to force an ``input``
|
|
event to be generated.
|
|
|
|
If ``key`` is a modifier key, like ``Shift``, ``Meta``, or ``Alt``,
|
|
subsequent key presses will be sent with that modifier active. To
|
|
release the modifier key, use :meth:`up` method.
|
|
|
|
:arg str key: Name of key to press, such as ``ArrowLeft``.
|
|
:arg dict options: Option can have ``text`` field, and if this option
|
|
specified, generate an input event with this text.
|
|
|
|
.. note::
|
|
Modifier keys DO influence :meth:`down`. Holding down ``shift``
|
|
will type the text in upper case.
|
|
"""
|
|
...
|
|
|
|
async def up(self, key: str) -> None:
|
|
"""Dispatch a ``keyup`` event of the ``key``.
|
|
|
|
:arg str key: Name of key to release, such as ``ArrowLeft``.
|
|
"""
|
|
...
|
|
|
|
async def sendCharacter(self, char: str) -> None:
|
|
"""Send character into the page.
|
|
|
|
This method dispatches a ``keypress`` and ``input`` event. This does
|
|
not send a ``keydown`` or ``keyup`` event.
|
|
|
|
.. note::
|
|
Modifier keys DO NOT effect :meth:`sendCharacter`. Holding down
|
|
``shift`` will not type the text in upper case.
|
|
"""
|
|
...
|
|
|
|
async def type(self, text: str, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
|
"""Type characters into a focused element.
|
|
|
|
This method sends ``keydown``, ``keypress``/``input``, and ``keyup``
|
|
event for each character in the ``text``.
|
|
|
|
To press a special key, like ``Control`` or ``ArrowDown``, use
|
|
:meth:`press` method.
|
|
|
|
:arg str text: Text to type into a focused element.
|
|
:arg dict options: Options can have ``delay`` (int|float) field, which
|
|
specifies time to wait between key presses in milliseconds. Defaults
|
|
to 0.
|
|
|
|
.. note::
|
|
Modifier keys DO NOT effect :meth:`type`. Holding down ``shift``
|
|
will not type the text in upper case.
|
|
"""
|
|
...
|
|
|
|
async def press(self, key: str, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
|
"""Press ``key``.
|
|
|
|
If ``key`` is a single character and no modifier keys besides
|
|
``Shift`` are being held down, a ``keypress``/``input`` event will also
|
|
generated. The ``text`` option can be specified to force an input event
|
|
to be generated.
|
|
|
|
:arg str key: Name of key to press, such as ``ArrowLeft``.
|
|
|
|
This method accepts the following options:
|
|
|
|
* ``text`` (str): If specified, generates an input event with this
|
|
text.
|
|
* ``delay`` (int|float): Time to wait between ``keydown`` and
|
|
``keyup``. Defaults to 0.
|
|
|
|
.. note::
|
|
Modifier keys DO effect :meth:`press`. Holding down ``Shift`` will
|
|
type the text in upper case.
|
|
"""
|
|
...
|
|
|
|
|
|
|
|
class Mouse:
|
|
"""Mouse class.
|
|
|
|
The :class:`Mouse` operates in main-frame CSS pixels relative to the
|
|
top-left corner of the viewport.
|
|
"""
|
|
def __init__(self, client: CDPSession, keyboard: Keyboard) -> None:
|
|
...
|
|
|
|
async def move(self, x: float, y: float, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
|
"""Move mouse cursor (dispatches a ``mousemove`` event).
|
|
|
|
Options can accepts ``steps`` (int) field. If this ``steps`` option
|
|
specified, Sends intermediate ``mousemove`` events. Defaults to 1.
|
|
"""
|
|
...
|
|
|
|
async def click(self, x: float, y: float, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
|
"""Click button at (``x``, ``y``).
|
|
|
|
Shortcut to :meth:`move`, :meth:`down`, and :meth:`up`.
|
|
|
|
This method accepts the following options:
|
|
|
|
* ``button`` (str): ``left``, ``right``, or ``middle``, defaults to
|
|
``left``.
|
|
* ``clickCount`` (int): defaults to 1.
|
|
* ``delay`` (int|float): Time to wait between ``mousedown`` and
|
|
``mouseup`` in milliseconds. Defaults to 0.
|
|
"""
|
|
...
|
|
|
|
async def down(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
|
"""Press down button (dispatches ``mousedown`` event).
|
|
|
|
This method accepts the following options:
|
|
|
|
* ``button`` (str): ``left``, ``right``, or ``middle``, defaults to
|
|
``left``.
|
|
* ``clickCount`` (int): defaults to 1.
|
|
"""
|
|
...
|
|
|
|
async def up(self, options: Dict[str, Any] = ..., **kwargs: Any) -> None:
|
|
"""Release pressed button (dispatches ``mouseup`` event).
|
|
|
|
This method accepts the following options:
|
|
|
|
* ``button`` (str): ``left``, ``right``, or ``middle``, defaults to
|
|
``left``.
|
|
* ``clickCount`` (int): defaults to 1.
|
|
"""
|
|
...
|
|
|
|
|
|
|
|
class Touchscreen:
|
|
"""Touchscreen class."""
|
|
def __init__(self, client: CDPSession, keyboard: Keyboard) -> None:
|
|
"""Make new touchscreen object."""
|
|
...
|
|
|
|
async def tap(self, x: float, y: float) -> None:
|
|
"""Tap (``x``, ``y``).
|
|
|
|
Dispatches a ``touchstart`` and ``touchend`` event.
|
|
"""
|
|
...
|
|
|
|
|
|
|