mokr.input ========== .. py:module:: mokr.input Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/mokr/input/dialog/index /autoapi/mokr/input/keyboard/index /autoapi/mokr/input/mouse/index /autoapi/mokr/input/touchscreen/index Classes ------- .. autoapisummary:: mokr.input.Dialog mokr.input.Keyboard mokr.input.Mouse mokr.input.Touchscreen Package Contents ---------------- .. py:class:: Dialog(client: mokr.connection.DevtoolsConnection, dialog_type: str, message: str, default_value: str | None = None) Dialog objects are initialised by the parent `mokr.browser.Page` when a dialog event is triggered. :param client: A `mokr.connection.DevtoolsConnection` spawned by the parent `mokr.browser.Page`. :type client: DevtoolsConnection :param dialog_type: Dialog type from the triggering event's type. :type dialog_type: str :param message: Message in the dialog. :type message: str :param default_value: Default prompt that the dialog spawned with. Defaults to None. :type default_value: str | None, optional Example:: async def close_dialog(dialog): print(dialog.message) await dialog.dismiss() page.on("dialog", close_dialog) .. py:property:: kind :type: str Get the remote `Dialog` event type. One of "alert", "beforeunload, "confirm", "prompt, or "". .. py:property:: message :type: str Get the message the dialog spawned with. .. py:property:: default_value :type: str Get default prompt value, if remote dialog type is "prompt". Otherwise, get "". .. py:method:: accept(prompt_text: str = '') -> None :async: Accept the remote dialog. Can optionally accept with the given `prompt_text`, if `Dialog.type` is "prompt". :param prompt_text: _description_. Defaults to ''. :type prompt_text: str, optional .. py:method:: dismiss() -> None :async: Dismiss the remote dialog. .. py:class:: Keyboard(client: mokr.connection.DevtoolsConnection) Class to allow sending key events to emulate a keyboard. Use `Keyboard.type("text")` to type text normally; this will dispacth multiple key events for each character in the given text. For finer control, use `Keyboard.down`, `Keyboard.up` and `Keyboard.send_character`. Special keys and modifier key can be sent. To view all key names and their associated event payload, use `Keyboard.key_definitions`. :param client: Remote `DevtoolsConnection` instance. :type client: DevtoolsConnection .. py:property:: key_definitions :type: dict[str, dict[str, str | int]] Dictionary of key names and their corresponding event codes. .. py:method:: down(key: str, text: str | None = None) -> None :async: Send a "keyDown" event with the given `key`. Does not automatically send a "keyUp" event, use `Keyboard.up` for that. Modifier keys effect this method, meaning sending `Keyboard.down("shift")` and then `Keyboard.down("m")` will type an uppercase "M". :param key: Name of key. See `Keyboard.key_definitions`. :type key: str :param text: Force an "input" event to be sent, as well. Defaults to None. :type text: str | None, optional .. py:method:: up(key: str) -> None :async: Send a "KeyUp" event with the given `key`. :param key: Name of key. See `Keyboard.key_definitions`. :type key: str :param text: Force an "input" event to be sent, as well. Defaults to None. :type text: str | None, optional .. py:method:: send_character(char: str) -> None :async: Send a character `char` into the parent `mokr.frame.Frame`. Does not send "keyDown" or "keyUp" event, only sends "keyPress" and "input". Modifier keys do not effect this method, meaning sending `Keyboard.down("shift")` and then `Keyboard.send_character("m")` will type a lowercase "m". :param char: Character to send, does not accept special characters. :type char: str .. py:method:: type_text(text: str, delay: int | float = 0) -> None :async: Type characters into the page; whatever element is focused will receive the sent input. Note that modifier keys do not alter text case, meaning sending `Keyboard.down("shift")` and typing `Keyboard.type_text("mokr")` will not type "MOKR". :param text: Text to type. :type text: str :param delay: Time in milliseconds to wait between each character typed. Defaults to 0. :type delay: int | float, optional .. py:method:: press(key: str, delay: int | float | None = None) -> None :async: Press the given `key` by sending `Keyboard.down` and `Keyboard.up` events, with the given `delay` in between. Modifier keys effect this method, meaning sending `Keyboard.down("shift")` and then `Keyboard.press("m")` will type an uppercase "M". :param key: Name of key. See `Keyboard.key_definitions`. :type key: str :param delay: Time in milliseconds to "hold" the key down. Defaults to None. :type delay: int | float | None, optional .. py:class:: Mouse(client: mokr.connection.DevtoolsConnection, keyboard: mokr.input.keyboard.Keyboard) Class to emulate mouse movement. The `Mouse`'s remote position is measured in pixels, with origin at the top-left corner of the viewport. :param client: Remote `DevtoolsConnection` instance. :type client: DevtoolsConnection :param keyboard: Active `mokr.input.Keyboard` from the parent `mokr.input.Keyboard`. Passes active modifiers such as CTRL. :type keyboard: Keyboard .. py:method:: move(x: float, y: float, steps: int = 1) -> None :async: Move the mouse to target coordinates (`x`, `y`), sending intermittent events along the trail for each step in `steps`. :param x: Target X coordinate. :type x: float :param y: Target Y coordinate. :type y: float :param steps: Number of times to stop along the path. Defaults to 1 (final destination only). :type steps: int, optional .. py:method:: down(button: Literal['left', 'right', 'middle'] = 'left', click_count: int = 1) -> None :async: Send a "mousePressed" event with given mouse `button`, repeat for `click_count` number of times. :param button: Mouse button to send with. Defaults to "left". :type button: Literal["left", "right", "middle"], optional :param click_count: Number of click events to send. Defaults to 1. :type click_count: int, optional .. py:method:: up(button: Literal['left', 'right', 'middle'] = 'left', click_count: int = 1) -> None :async: Send a "mouseReleased" event with given mouse `button`, repeat for `click_count` number of times. :param button: Mouse button to send with. Defaults to "left". :type button: Literal["left", "right", "middle"], optional :param click_count: Number of click events to send. Defaults to 1. :type click_count: int, optional .. py:method:: click(x: float, y: float, button: Literal['left', 'right', 'middle'] = 'left', click_count: int = 1, delay: int | float | None = 1000) -> None :async: Move the pointer to the target coordinates and click. Shortcut to running `Mouse.move` then `Mouse.down` then `Mouse.up`. :param x: X coordinate to move to. :type x: float :param y: Y coordinate to move to. :type y: float :param button: Mouse button to click with. Defaults to "left". :type button: Literal["left", "right", "middle"], optional :param click_count: Number of clicks to run. Defaults to 1. :type click_count: int, optional :param delay: Time in milliseconds to wait before each click. Defaults to 1000. :type delay: int | float | None, optional .. py:class:: Touchscreen(client: mokr.connection.DevtoolsConnection, keyboard: mokr.input.keyboard.Keyboard) Class to emulate touchscreen. :param client: Remote `DevtoolsConnection` instance. :type client: DevtoolsConnection :param keyboard: Active `mokr.input.Keyboard` from the parent `mokr.input.Keyboard`. Passes active modifiers such as CTRL. :type keyboard: Keyboard .. py:method:: tap(x: float, y: float) -> None :async: Send touch down and up events to the center of the target coordinates. :param x: X coordinate to move to. :type x: float :param y: Y coordinate to move to. :type y: float