mokr.input.keyboard
Module Contents
Classes
Class to allow sending key events to emulate a keyboard. |
- class mokr.input.keyboard.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.upandKeyboard.send_character.Special keys and modifier key can be sent. To view all key names and their associated event payload, use
Keyboard.key_definitions.- Parameters:
client (DevtoolsConnection) – Remote
DevtoolsConnectioninstance.
- property key_definitions: dict[str, dict[str, str | int]]
Dictionary of key names and their corresponding event codes.
- async down(key: str, text: str | None = None) None
Send a “keyDown” event with the given
key. Does not automatically send a “keyUp” event, useKeyboard.upfor that.Modifier keys effect this method, meaning sending
Keyboard.down("shift")and thenKeyboard.down("m")will type an uppercase “M”.- Parameters:
key (str) – Name of key. See
Keyboard.key_definitions.text (str | None, optional) – Force an “input” event to be sent, as well. Defaults to None.
- async up(key: str) None
Send a “KeyUp” event with the given
key.- Parameters:
key (str) – Name of key. See
Keyboard.key_definitions.text (str | None, optional) – Force an “input” event to be sent, as well. Defaults to None.
- async send_character(char: str) None
Send a character
charinto the parentmokr.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 thenKeyboard.send_character("m")will type a lowercase “m”.- Parameters:
char (str) – Character to send, does not accept special characters.
- async type_text(text: str, delay: int | float = 0) None
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 typingKeyboard.type_text("mokr")will not type “MOKR”.- Parameters:
text (str) – Text to type.
delay (int | float, optional) – Time in milliseconds to wait between each character typed. Defaults to 0.
- async press(key: str, delay: int | float | None = None) None
Press the given
keyby sendingKeyboard.downandKeyboard.upevents, with the givendelayin between.Modifier keys effect this method, meaning sending
Keyboard.down("shift")and thenKeyboard.press("m")will type an uppercase “M”.- Parameters:
key (str) – Name of key. See
Keyboard.key_definitions.delay (int | float | None, optional) – Time in milliseconds to “hold” the key down. Defaults to None.