Skip to main content

Controller

Struct Controller 

Source
pub struct Controller { /* private fields */ }
Expand description

Device controller interface.

Handles interaction with the target device, including:

  • Input events (click, swipe, key press)
  • Screen capture
  • App management (start/stop)
  • Connection management

See also: AdbControllerBuilder for advanced ADB configuration.

Implementations§

Source§

impl Controller

Source

pub fn new_adb( adb_path: &str, address: &str, config: &str, agent_path: Option<&str>, ) -> MaaResult<Self>

Create a new ADB controller for Android device control.

§Arguments
  • adb_path - Path to the ADB executable
  • address - Device address (e.g., “127.0.0.1:5555” or “emulator-5554”)
  • config - JSON configuration string for advanced options
  • agent_path - Optional path to MaaAgentBinary
Source

pub fn new_win32( hwnd: *mut c_void, screencap_method: MaaWin32ScreencapMethod, mouse_method: MaaWin32InputMethod, keyboard_method: MaaWin32InputMethod, ) -> MaaResult<Self>

Create a new Win32 controller for Windows window control.

Source

pub fn new_playcover(address: &str, uuid: &str) -> MaaResult<Self>

Create a new PlayCover controller for iOS app control on macOS.

Source

pub fn new_custom<T: CustomControllerCallback + 'static>( callback: T, ) -> MaaResult<Self>

Create a custom controller with user-defined callbacks.

Source

pub fn post_click(&self, x: i32, y: i32) -> MaaResult<MaaId>

Post a click action at the specified coordinates.

Source

pub fn post_screencap(&self) -> MaaResult<MaaId>

Post a screenshot capture request.

Source

pub fn post_click_v2( &self, x: i32, y: i32, contact: i32, pressure: i32, ) -> MaaResult<MaaId>

Post a click action with contact and pressure parameters.

§Arguments
  • x, y - Click coordinates
  • contact - Contact/finger index (for multi-touch)
  • pressure - Touch pressure (1 = normal)
Source

pub fn post_swipe( &self, x1: i32, y1: i32, x2: i32, y2: i32, duration: i32, ) -> MaaResult<MaaId>

Post a swipe action from one point to another.

§Arguments
  • x1, y1 - Start coordinates
  • x2, y2 - End coordinates
  • duration - Swipe duration in milliseconds
Source

pub fn post_click_key(&self, keycode: i32) -> MaaResult<MaaId>

Post a key click action.

§Arguments
  • keycode - Virtual key code (ADB keycode for Android, VK for Win32)
Source

pub fn post_press(&self, keycode: i32) -> MaaResult<MaaId>

👎Deprecated: Use post_click_key instead

Alias for post_click_key.

Source

pub fn post_input_text(&self, text: &str) -> MaaResult<MaaId>

Post a text input action.

§Arguments
  • text - Text to input
Source

pub fn post_shell(&self, cmd: &str, timeout: i64) -> MaaResult<MaaId>

Post a shell command execution (ADB only).

§Arguments
  • cmd - Shell command to execute
  • timeout - Timeout in milliseconds
Source

pub fn post_touch_down( &self, contact: i32, x: i32, y: i32, pressure: i32, ) -> MaaResult<MaaId>

Post a touch down event.

§Arguments
  • contact - Contact/finger index
  • x, y - Touch coordinates
  • pressure - Touch pressure
Source

pub fn post_touch_move( &self, contact: i32, x: i32, y: i32, pressure: i32, ) -> MaaResult<MaaId>

Post a touch move event.

§Arguments
  • contact - Contact/finger index
  • x, y - New touch coordinates
  • pressure - Touch pressure
Source

pub fn post_touch_up(&self, contact: i32) -> MaaResult<MaaId>

Post a touch up event.

§Arguments
  • contact - Contact/finger index to release
Source

pub fn raw(&self) -> *mut MaaController

Returns the underlying raw controller handle.

Source

pub fn post_connection(&self) -> MaaResult<MaaId>

Post a connection request to the device.

Returns a job ID that can be used with wait to block until connected.

Source

pub fn connected(&self) -> bool

Returns true if the controller is connected to the device.

Source

pub fn uuid(&self) -> MaaResult<String>

Gets the unique identifier (UUID) of the connected device.

Source

pub fn resolution(&self) -> MaaResult<(i32, i32)>

Gets the device screen resolution as (width, height).

Source

pub fn post_swipe_v2( &self, x1: i32, y1: i32, x2: i32, y2: i32, duration: i32, contact: i32, pressure: i32, ) -> MaaResult<MaaId>

Post a swipe action with contact and pressure parameters.

§Arguments
  • x1, y1 - Start coordinates
  • x2, y2 - End coordinates
  • duration - Swipe duration in milliseconds
  • contact - Contact/finger index
  • pressure - Touch pressure
Source

pub fn post_key_down(&self, keycode: i32) -> MaaResult<MaaId>

Post a key down event.

Source

pub fn post_key_up(&self, keycode: i32) -> MaaResult<MaaId>

Post a key up event.

Source

pub fn post_start_app(&self, intent: &str) -> MaaResult<MaaId>

Start an application.

§Arguments
  • intent - Package name or activity (ADB), app identifier (Win32)
Source

pub fn post_stop_app(&self, intent: &str) -> MaaResult<MaaId>

Stop an application.

§Arguments
  • intent - Package name (ADB)
Source

pub fn post_scroll(&self, dx: i32, dy: i32) -> MaaResult<MaaId>

Post a scroll action (Win32 only).

§Arguments
  • dx - Horizontal scroll delta (positive = right)
  • dy - Vertical scroll delta (positive = down)
Source

pub fn cached_image(&self) -> MaaResult<MaaImageBuffer>

Gets the most recently captured screenshot.

Source

pub fn shell_output(&self) -> MaaResult<String>

Gets the output from the most recent shell command (ADB only).

Source

pub fn status(&self, ctrl_id: MaaId) -> MaaStatus

Gets the status of a controller operation.

Source

pub fn wait(&self, ctrl_id: MaaId) -> MaaStatus

Blocks until a controller operation completes.

Source

pub fn set_screenshot_target_long_side(&self, long_side: i32) -> MaaResult<()>

Sets the target long side for screenshot scaling.

Source

pub fn set_screenshot_target_short_side(&self, short_side: i32) -> MaaResult<()>

Sets the target short side for screenshot scaling.

Source

pub fn set_screenshot_use_raw_size(&self, enable: bool) -> MaaResult<()>

Sets whether to use raw (unscaled) screenshot resolution.

Source

pub fn new_dbg( read_path: &str, write_path: &str, dbg_type: MaaDbgControllerType, config: &str, ) -> MaaResult<Self>

Source

pub fn new_gamepad( hwnd: *mut c_void, gamepad_type: GamepadType, screencap_method: Win32ScreencapMethod, ) -> MaaResult<Self>

Create a virtual gamepad controller (Windows only).

Source

pub fn add_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
where F: Fn(&str, &str) + Send + Sync + 'static,

Returns sink_id for later removal. Callback lifetime managed by caller.

Source

pub fn add_event_sink(&self, sink: Box<dyn EventSink>) -> MaaResult<MaaSinkId>

Register a strongly-typed event sink.

This method registers an implementation of the EventSink trait to receive structured notifications from this controller.

§Arguments
  • sink - The event sink implementation (must be boxed).
§Returns

A MaaSinkId which can be used to manually remove the sink later via remove_sink. The sink will be automatically unregistered and dropped when the Controller is dropped.

Source

pub fn remove_sink(&self, sink_id: MaaSinkId)

Source

pub fn clear_sinks(&self)

Trait Implementations§

Source§

impl Clone for Controller

Source§

fn clone(&self) -> Controller

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Controller

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Send for Controller

Source§

impl Sync for Controller

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.