mokr.input.keyboard =================== .. py:module:: mokr.input.keyboard Classes ------- .. autoapisummary:: mokr.input.keyboard.Keyboard Module Contents --------------- .. 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