External programs can control Scrcpy Mask by connecting via WebSocket and invoking the external control interface provided by Scrcpy Mask. This includes sending touch events, key events, and more to the controlled Android device.
This repository provides control instructions, interface documentation, and offers control utility classes and code examples in several common languages.
External programs start a WebSocket Server, fill in the WebSocket Server address in the external control input box on the Scrcpy Mask device page, and click connect to establish a connection.
After successful connection, external programs can call the respective interfaces by sending specific formatted JSON strings, known as request messages, to Scrcpy Mask via WebSocket. If the interface has a return value, Scrcpy Mask will respond with a JSON string formatted as a response message.
External programs can attach a random
msgID
field when sending the request JSON string. Scrcpy Mask will include the samemsgID
when replying to the request. External programs can use this to identify which response message corresponds to which request message.
Display a message of a specific type at the top of the Scrcpy Mask window.
{
"type": "showMessage",
"msgType": "success" | "info" | "warning" | "error",
"msgContent": string
}
No return value
Retrieve information about the Android device currently controlled by Scrcpy Mask, returns null if no device is being controlled.
{
"type": "getControlledDevice"
}
{
"msgID": string,
"controledDevice": {
"scid": string,
"deviceName": string,
"deviceID": string
}
}
// or
{
"msgID": string,
"controledDevice": null
}
Send a key event to the controlled device.
{
"type": "sendKey",
"action": number, // SendKeyAction: Default = 0, Down = 1, Up = 2
"keycode": number, // AndroidKeycode
"metastate": number // Optional. AndroidMetastate: can be combined by Bitwise OR operation
}
Refer to src/frontcommand/scrcpyMaskCmd.ts
and src/frontcommand/android.ts
for specific values.
No return value
Send a touch event to the controlled device.
{
"type": "touch",
"action": number, // TouchAction: Default = 0, Down = 1, Up = 2, Move = 3
"pointerId": number,
"pos": { "x": number; "y": number }, // pos relative to Android device
"time": number // Optional. valid only when action is Default, default 80 milliseconds
}
No return value
Send a swipe event to the controlled device, including coordinates of all turning points in the swipe path.
For longer path segments, it will automatically split into multiple shorter segments.
{
"type": "swipe",
"action": number, // SwipeAction: Default = 0, NoUp = 1, NoDown = 2
"pointerId": number,
"pos": { "x": number; "y": number }[], // pos path array relative to Android device
"intervalBetweenPos": number
}
No return value
Terminate control of the controlled device.
{
"type": "shutdown"
}
No return value
Interfaces in the controlMsg.ts
file are currently not needed and will not be added for now.