Overview
The keys module provides classes and utilities for handling keyboard input and generating CDP-compatible key events. It supports ASCII characters, special keys, modifier combinations, emojis, and grapheme clusters.KeyEvents
Key events handling class for processing keyboard input and converting to CDP format.Constructor
The key to be processed (single character string or SpecialKeys enum)
Modifier keys to be applied (can be combined with bitwise OR)
Methods
to_cdp_events
Convert the key event to CDP format.The type of key press event to generate. Currently supported are
DOWN_AND_UP and CHAROptional modifiers to override the current ones
List[KeyEvents.Payload] - List of dictionaries containing CDP payload
Example:
from_text
Create KeyEvents payloads from a text string, automatically handling special characters and graphemes.The text to convert to key events
The key press event to use for ASCII characters
List[KeyEvents.Payload] - List of KeyEvents.Payload objects ready for CDP
Example:
from_mixed_input
Create KeyEvents payloads from a mixed sequence of strings, special keys, and key+modifier combinations.List containing:
str: Regular text (will be processed character by character)SpecialKeys: Special keys (will use DOWN_AND_UP)Tuple[key, modifiers]: Key with modifiers (will use DOWN_AND_UP)
The key press event to use for ASCII characters
List[KeyEvents.Payload] - List of KeyEvents.Payload objects ready for CDP
Example:
is_english_alphabet
Check if a character is an English alphabet letter (A-Z, a-z).The character to check
bool - True if the character is an English alphabet letter, False otherwise
KeyModifiers
Enumeration of keyboard modifiers used in key events. For multiple modifiers, use bitwise OR to combine them.Values
Default(0) - No modifiersAlt(1) - Alt keyCtrl(2) - Control keyMeta(4) - Meta/Command keyShift(8) - Shift key
Example
SpecialKeys
Enumeration of special keys with their corresponding names and key codes.Values
SPACE- Space keyENTER- Enter keyTAB- Tab keyBACKSPACE- Backspace keyESCAPE- Escape keyDELETE- Delete keyARROW_LEFT- Left arrow keyARROW_UP- Up arrow keyARROW_RIGHT- Right arrow keyARROW_DOWN- Down arrow keySHIFT- Shift key (internal use only)ALT- Alt key (internal use only)CTRL- Control key (internal use only)META- Meta key (internal use only)
Example
KeyPressEvent
Enumeration of different types of key press events.Values
KEY_DOWN- Key down event (not supported by itself)KEY_UP- Key up event (not supported by itself)RAW_KEY_DOWN- Raw key down event (not supported by itself)CHAR- Directly sends ASCII character to the element. Cannot send non-ASCII characters and commands (Ctrl+A, etc.)DOWN_AND_UP- Way to give both key down and up events in one go for non-ASCII characters (not standard implementation)