Input

Types

Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.

class cdp.input_.TouchPoint(x, y, radius_x=None, radius_y=None, rotation_angle=None, force=None, id_=None)
force = None

Force (default: 1.0).

id_ = None

Identifier used to track touch sources between events, must be unique within an event.

radius_x = None

X radius of the touch area (default: 1.0).

radius_y = None

Y radius of the touch area (default: 1.0).

rotation_angle = None

Rotation angle (default: 0.0).

x = None

X coordinate of the event relative to the main frame’s viewport in CSS pixels.

y = None

Y coordinate of the event relative to the main frame’s viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.

class cdp.input_.GestureSourceType

An enumeration.

DEFAULT = 'default'
MOUSE = 'mouse'
TOUCH = 'touch'
class cdp.input_.TimeSinceEpoch

UTC time in seconds, counted from January 1, 1970.

Commands

Each command is a generator function. The return type Generator[x, y, z] indicates that the generator yields arguments of type x, it must be resumed with an argument of type y, and it returns type z. In this library, types x and y are the same for all commands, and z is the return type you should pay attention to. For more information, see Getting Started: Commands.

cdp.input_.dispatch_key_event(type_, modifiers=None, timestamp=None, text=None, unmodified_text=None, key_identifier=None, code=None, key=None, windows_virtual_key_code=None, native_virtual_key_code=None, auto_repeat=None, is_keypad=None, is_system_key=None, location=None)

Dispatches a key event to the page.

Parameters:
  • type – Type of the key event.
  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  • timestamp (Optional[TimeSinceEpoch]) – (Optional) Time at which the event occurred.
  • text (Optional[str]) – (Optional) Text as generated by processing a virtual key code with a keyboard layout. Not needed for for `keyUp`` and ``rawKeyDown` events (default: “”)
  • unmodified_text (Optional[str]) – (Optional) Text that would have been generated by the keyboard if no modifiers were pressed (except for shift). Useful for shortcut (accelerator) key handling (default: “”).
  • key_identifier (Optional[str]) – (Optional) Unique key identifier (e.g., ‘U+0041’) (default: “”).
  • code (Optional[str]) – (Optional) Unique DOM defined string value for each physical key (e.g., ‘KeyA’) (default: “”).
  • key (Optional[str]) – (Optional) Unique DOM defined string value describing the meaning of the key in the context of active modifiers, keyboard layout, etc (e.g., ‘AltGr’) (default: “”).
  • windows_virtual_key_code (Optional[int]) – (Optional) Windows virtual key code (default: 0).
  • native_virtual_key_code (Optional[int]) – (Optional) Native virtual key code (default: 0).
  • auto_repeat (Optional[bool]) – (Optional) Whether the event was generated from auto repeat (default: false).
  • is_keypad (Optional[bool]) – (Optional) Whether the event was generated from the keypad (default: false).
  • is_system_key (Optional[bool]) – (Optional) Whether the event was a system key event (default: false).
  • location (Optional[int]) – (Optional) Whether the event was from the left or right side of the keyboard. 1=Left, 2=Right (default: 0).
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.input_.dispatch_mouse_event(type_, x, y, modifiers=None, timestamp=None, button=None, buttons=None, click_count=None, delta_x=None, delta_y=None, pointer_type=None)

Dispatches a mouse event to the page.

Parameters:
  • type – Type of the mouse event.
  • x (float) – X coordinate of the event relative to the main frame’s viewport in CSS pixels.
  • y (float) – Y coordinate of the event relative to the main frame’s viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  • timestamp (Optional[TimeSinceEpoch]) – (Optional) Time at which the event occurred.
  • button (Optional[str]) – (Optional) Mouse button (default: “none”).
  • buttons (Optional[int]) – (Optional) A number indicating which buttons are pressed on the mouse when a mouse event is triggered. Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.
  • click_count (Optional[int]) – (Optional) Number of times the mouse button was clicked (default: 0).
  • delta_x (Optional[float]) – (Optional) X delta in CSS pixels for mouse wheel event (default: 0).
  • delta_y (Optional[float]) – (Optional) Y delta in CSS pixels for mouse wheel event (default: 0).
  • pointer_type (Optional[str]) – (Optional) Pointer type (default: “mouse”).
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.input_.dispatch_touch_event(type_, touch_points, modifiers=None, timestamp=None)

Dispatches a touch event to the page.

Parameters:
  • type – Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while TouchStart and TouchMove must contains at least one.
  • touch_points (List[TouchPoint]) – Active touch points on the touch device. One event per any changed point (compared to previous touch event in a sequence) is generated, emulating pressing/moving/releasing points one by one.
  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  • timestamp (Optional[TimeSinceEpoch]) – (Optional) Time at which the event occurred.
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.input_.emulate_touch_from_mouse_event(type_, x, y, button, timestamp=None, delta_x=None, delta_y=None, modifiers=None, click_count=None)

Emulates touch event from the mouse event parameters.

EXPERIMENTAL

Parameters:
  • type – Type of the mouse event.
  • x (int) – X coordinate of the mouse pointer in DIP.
  • y (int) – Y coordinate of the mouse pointer in DIP.
  • button (str) – Mouse button.
  • timestamp (Optional[TimeSinceEpoch]) – (Optional) Time at which the event occurred (default: current time).
  • delta_x (Optional[float]) – (Optional) X delta in DIP for mouse wheel event (default: 0).
  • delta_y (Optional[float]) – (Optional) Y delta in DIP for mouse wheel event (default: 0).
  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).
  • click_count (Optional[int]) – (Optional) Number of times the mouse button was clicked (default: 0).
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.input_.insert_text(text)

This method emulates inserting text that doesn’t come from a key press, for example an emoji keyboard or an IME.

EXPERIMENTAL

Parameters:text (str) – The text to insert.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.input_.set_ignore_input_events(ignore)

Ignores input events (useful while auditing page).

Parameters:ignore (bool) – Ignores input events processing when set to true.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.input_.synthesize_pinch_gesture(x, y, scale_factor, relative_speed=None, gesture_source_type=None)

Synthesizes a pinch gesture over a time period by issuing appropriate touch events.

EXPERIMENTAL

Parameters:
  • x (float) – X coordinate of the start of the gesture in CSS pixels.
  • y (float) – Y coordinate of the start of the gesture in CSS pixels.
  • scale_factor (float) – Relative scale factor after zooming (>1.0 zooms in, <1.0 zooms out).
  • relative_speed (Optional[int]) – (Optional) Relative pointer speed in pixels per second (default: 800).
  • gesture_source_type (Optional[GestureSourceType]) – (Optional) Which type of input events to be generated (default: ‘default’, which queries the platform for the preferred input type).
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.input_.synthesize_scroll_gesture(x, y, x_distance=None, y_distance=None, x_overscroll=None, y_overscroll=None, prevent_fling=None, speed=None, gesture_source_type=None, repeat_count=None, repeat_delay_ms=None, interaction_marker_name=None)

Synthesizes a scroll gesture over a time period by issuing appropriate touch events.

EXPERIMENTAL

Parameters:
  • x (float) – X coordinate of the start of the gesture in CSS pixels.
  • y (float) – Y coordinate of the start of the gesture in CSS pixels.
  • x_distance (Optional[float]) – (Optional) The distance to scroll along the X axis (positive to scroll left).
  • y_distance (Optional[float]) – (Optional) The distance to scroll along the Y axis (positive to scroll up).
  • x_overscroll (Optional[float]) – (Optional) The number of additional pixels to scroll back along the X axis, in addition to the given distance.
  • y_overscroll (Optional[float]) – (Optional) The number of additional pixels to scroll back along the Y axis, in addition to the given distance.
  • prevent_fling (Optional[bool]) – (Optional) Prevent fling (default: true).
  • speed (Optional[int]) – (Optional) Swipe speed in pixels per second (default: 800).
  • gesture_source_type (Optional[GestureSourceType]) – (Optional) Which type of input events to be generated (default: ‘default’, which queries the platform for the preferred input type).
  • repeat_count (Optional[int]) – (Optional) The number of times to repeat the gesture (default: 0).
  • repeat_delay_ms (Optional[int]) – (Optional) The number of milliseconds delay between each repeat. (default: 250).
  • interaction_marker_name (Optional[str]) – (Optional) The name of the interaction markers to generate, if not empty (default: “”).
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.input_.synthesize_tap_gesture(x, y, duration=None, tap_count=None, gesture_source_type=None)

Synthesizes a tap gesture over a time period by issuing appropriate touch events.

EXPERIMENTAL

Parameters:
  • x (float) – X coordinate of the start of the gesture in CSS pixels.
  • y (float) – Y coordinate of the start of the gesture in CSS pixels.
  • duration (Optional[int]) – (Optional) Duration between touchdown and touchup events in ms (default: 50).
  • tap_count (Optional[int]) – (Optional) Number of times to perform the tap (e.g. 2 for double tap, default: 1).
  • gesture_source_type (Optional[GestureSourceType]) – (Optional) Which type of input events to be generated (default: ‘default’, which queries the platform for the preferred input type).
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

Events

There are no events in this module.