API

Module description

Python Scrcpy Client’s core module

Submodules

scrcpy.core module

class scrcpy.core.Client(device: Optional[Union[adbutils._device.AdbDevice, str, any]] = None, max_width: int = 0, bitrate: int = 8000000, max_fps: int = 0, flip: bool = False, block_frame: bool = False, stay_awake: bool = False, lock_screen_orientation: int = - 1, connection_timeout: int = 3000, encoder_name: Optional[str] = None)[source]

Bases: object

add_listener(cls: str, listener: Callable[[...], Any]) None[source]

Add a video listener

Parameters
  • cls – Listener category, support: init, frame

  • listener – A function to receive frame np.ndarray

remove_listener(cls: str, listener: Callable[[...], Any]) None[source]

Remove a video listener

Parameters
  • cls – Listener category, support: init, frame

  • listener – A function to receive frame np.ndarray

start(threaded: bool = False, daemon_threaded: bool = False) None[source]

Start listening video stream

Parameters
  • threaded – Run stream loop in a different thread to avoid blocking

  • daemon_threaded – Run stream loop in a daemon thread to avoid blocking

stop() None[source]

Stop listening (both threaded and blocked)

scrcpy.control module

class scrcpy.control.ControlSender(parent)[source]

Bases: object

back_or_turn_screen_on(action: int = 0) bytes[source]

If the screen is off, it is turned on only on ACTION_DOWN

Parameters

action – ACTION_DOWN | ACTION_UP

collapse_panels() bytes[source]

Collapse all panels

expand_notification_panel() bytes[source]

Expand notification panel

expand_settings_panel() bytes[source]

Expand settings panel

get_clipboard() str[source]

Get clipboard

keycode(keycode: int, action: int = 0, repeat: int = 0) bytes[source]

Send keycode to device

Parameters
  • keycode – const.KEYCODE_*

  • action – ACTION_DOWN | ACTION_UP

  • repeat – repeat count

rotate_device() bytes[source]

Rotate device

scroll(x: int, y: int, h: int, v: int) bytes[source]

Scroll screen

Parameters
  • x – horizontal position

  • y – vertical position

  • h – horizontal movement

  • v – vertical movement

set_clipboard(text: str, paste: bool = False) bytes[source]

Set clipboard

Parameters
  • text – the string you want to set

  • paste – paste now

set_screen_power_mode(mode: int = 2) bytes[source]

Set screen power mode

Parameters

mode – POWER_MODE_OFF | POWER_MODE_NORMAL

swipe(start_x: int, start_y: int, end_x: int, end_y: int, move_step_length: int = 5, move_steps_delay: float = 0.005) None[source]

Swipe on screen

Parameters
  • start_x – start horizontal position

  • start_y – start vertical position

  • end_x – start horizontal position

  • end_y – end vertical position

  • move_step_length – length per step

  • move_steps_delay – sleep seconds after each step

Returns

text(text: str) bytes[source]

Send text to device

Parameters

text – text to send

touch(x: int, y: int, action: int = 0, touch_id: int = - 1) bytes[source]

Touch screen

Parameters
  • x – horizontal position

  • y – vertical position

  • action – ACTION_DOWN | ACTION_UP | ACTION_MOVE

  • touch_id – Default using virtual id -1, you can specify it to emulate multi finger touch

scrcpy.control.inject(control_type: int)[source]

Inject control code, with this inject, we will be able to do unit test

Parameters

control_type – event to send, TYPE_*

scrcpy.const module

This module includes all consts used in this project