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
impl Controller
Sourcepub fn new_adb(
adb_path: &str,
address: &str,
config: &str,
agent_path: Option<&str>,
) -> MaaResult<Self>
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 executableaddress- Device address (e.g., “127.0.0.1:5555” or “emulator-5554”)config- JSON configuration string for advanced optionsagent_path- Optional path to MaaAgentBinary
Sourcepub fn new_win32(
hwnd: *mut c_void,
screencap_method: MaaWin32ScreencapMethod,
mouse_method: MaaWin32InputMethod,
keyboard_method: MaaWin32InputMethod,
) -> MaaResult<Self>
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.
Sourcepub fn new_playcover(address: &str, uuid: &str) -> MaaResult<Self>
pub fn new_playcover(address: &str, uuid: &str) -> MaaResult<Self>
Create a new PlayCover controller for iOS app control on macOS.
Sourcepub fn new_custom<T: CustomControllerCallback + 'static>(
callback: T,
) -> MaaResult<Self>
pub fn new_custom<T: CustomControllerCallback + 'static>( callback: T, ) -> MaaResult<Self>
Create a custom controller with user-defined callbacks.
Sourcepub fn post_click(&self, x: i32, y: i32) -> MaaResult<MaaId>
pub fn post_click(&self, x: i32, y: i32) -> MaaResult<MaaId>
Post a click action at the specified coordinates.
Sourcepub fn post_screencap(&self) -> MaaResult<MaaId>
pub fn post_screencap(&self) -> MaaResult<MaaId>
Post a screenshot capture request.
Sourcepub fn post_click_v2(
&self,
x: i32,
y: i32,
contact: i32,
pressure: i32,
) -> MaaResult<MaaId>
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 coordinatescontact- Contact/finger index (for multi-touch)pressure- Touch pressure (1 = normal)
Sourcepub fn post_swipe(
&self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
duration: i32,
) -> MaaResult<MaaId>
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 coordinatesx2,y2- End coordinatesduration- Swipe duration in milliseconds
Sourcepub fn post_click_key(&self, keycode: i32) -> MaaResult<MaaId>
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)
Sourcepub fn post_press(&self, keycode: i32) -> MaaResult<MaaId>
👎Deprecated: Use post_click_key instead
pub fn post_press(&self, keycode: i32) -> MaaResult<MaaId>
Alias for post_click_key.
Sourcepub fn post_input_text(&self, text: &str) -> MaaResult<MaaId>
pub fn post_input_text(&self, text: &str) -> MaaResult<MaaId>
Sourcepub fn post_shell(&self, cmd: &str, timeout: i64) -> MaaResult<MaaId>
pub fn post_shell(&self, cmd: &str, timeout: i64) -> MaaResult<MaaId>
Post a shell command execution (ADB only).
§Arguments
cmd- Shell command to executetimeout- Timeout in milliseconds
Sourcepub fn post_touch_down(
&self,
contact: i32,
x: i32,
y: i32,
pressure: i32,
) -> MaaResult<MaaId>
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 indexx,y- Touch coordinatespressure- Touch pressure
Sourcepub fn post_touch_move(
&self,
contact: i32,
x: i32,
y: i32,
pressure: i32,
) -> MaaResult<MaaId>
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 indexx,y- New touch coordinatespressure- Touch pressure
Sourcepub fn post_touch_up(&self, contact: i32) -> MaaResult<MaaId>
pub fn post_touch_up(&self, contact: i32) -> MaaResult<MaaId>
Sourcepub fn raw(&self) -> *mut MaaController
pub fn raw(&self) -> *mut MaaController
Returns the underlying raw controller handle.
Sourcepub fn post_connection(&self) -> MaaResult<MaaId>
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.
Sourcepub fn uuid(&self) -> MaaResult<String>
pub fn uuid(&self) -> MaaResult<String>
Gets the unique identifier (UUID) of the connected device.
Sourcepub fn resolution(&self) -> MaaResult<(i32, i32)>
pub fn resolution(&self) -> MaaResult<(i32, i32)>
Gets the device screen resolution as (width, height).
Sourcepub fn post_swipe_v2(
&self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
duration: i32,
contact: i32,
pressure: i32,
) -> MaaResult<MaaId>
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 coordinatesx2,y2- End coordinatesduration- Swipe duration in millisecondscontact- Contact/finger indexpressure- Touch pressure
Sourcepub fn post_key_down(&self, keycode: i32) -> MaaResult<MaaId>
pub fn post_key_down(&self, keycode: i32) -> MaaResult<MaaId>
Post a key down event.
Sourcepub fn post_key_up(&self, keycode: i32) -> MaaResult<MaaId>
pub fn post_key_up(&self, keycode: i32) -> MaaResult<MaaId>
Post a key up event.
Sourcepub fn post_start_app(&self, intent: &str) -> MaaResult<MaaId>
pub fn post_start_app(&self, intent: &str) -> MaaResult<MaaId>
Sourcepub fn post_stop_app(&self, intent: &str) -> MaaResult<MaaId>
pub fn post_stop_app(&self, intent: &str) -> MaaResult<MaaId>
Sourcepub fn post_scroll(&self, dx: i32, dy: i32) -> MaaResult<MaaId>
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)
Sourcepub fn cached_image(&self) -> MaaResult<MaaImageBuffer>
pub fn cached_image(&self) -> MaaResult<MaaImageBuffer>
Gets the most recently captured screenshot.
Sourcepub fn shell_output(&self) -> MaaResult<String>
pub fn shell_output(&self) -> MaaResult<String>
Gets the output from the most recent shell command (ADB only).
Sourcepub fn set_screenshot_target_long_side(&self, long_side: i32) -> MaaResult<()>
pub fn set_screenshot_target_long_side(&self, long_side: i32) -> MaaResult<()>
Sets the target long side for screenshot scaling.
Sourcepub fn set_screenshot_target_short_side(&self, short_side: i32) -> MaaResult<()>
pub fn set_screenshot_target_short_side(&self, short_side: i32) -> MaaResult<()>
Sets the target short side for screenshot scaling.
Sourcepub fn set_screenshot_use_raw_size(&self, enable: bool) -> MaaResult<()>
pub fn set_screenshot_use_raw_size(&self, enable: bool) -> MaaResult<()>
Sets whether to use raw (unscaled) screenshot resolution.
pub fn new_dbg( read_path: &str, write_path: &str, dbg_type: MaaDbgControllerType, config: &str, ) -> MaaResult<Self>
Sourcepub fn new_gamepad(
hwnd: *mut c_void,
gamepad_type: GamepadType,
screencap_method: Win32ScreencapMethod,
) -> MaaResult<Self>
pub fn new_gamepad( hwnd: *mut c_void, gamepad_type: GamepadType, screencap_method: Win32ScreencapMethod, ) -> MaaResult<Self>
Create a virtual gamepad controller (Windows only).
Sourcepub fn add_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
pub fn add_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
Returns sink_id for later removal. Callback lifetime managed by caller.
Sourcepub fn add_event_sink(&self, sink: Box<dyn EventSink>) -> MaaResult<MaaSinkId>
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.
pub fn remove_sink(&self, sink_id: MaaSinkId)
pub fn clear_sinks(&self)
Trait Implementations§
Source§impl Clone for Controller
impl Clone for Controller
Source§fn clone(&self) -> Controller
fn clone(&self) -> Controller
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more