Global Shortcut Events
Overview
Shortcut events encapsulated in the global module.
Click Functions
clickPoint Click by coordinates
- Click at coordinates
- @param x X coordinate
- @param y Y coordinate
- @return boolean
function main() { var result = clickPoint(100, 100); if (result) { logd("Click succeeded"); } else { logd("Click failed"); }}
main();clickPointPressure Click coordinates with pressure
- Click at coordinates with pressure
- Requires EC standalone 2.1.0+
- @param x X coordinate
- @param y Y coordinate
- @param pressure Pressure value in the range 0–1
- @return
{boolean}
function main() { var result = clickPointPressure(100, 100, 0.2); if (result) { logd("Click succeeded"); } else { logd("Click failed"); }}
main();longClickPoint Long-click by coordinates
- Long-click at coordinates
- @param x X coordinate
- @param y Y coordinate
- @return
{boolean}
function main() { var result = longClickPoint(100, 100); if (result) { logd("Click succeeded"); } else { logd("Click failed"); }}
main();doubleClickPoint Double-click by coordinates
- Double-click at coordinates
- @param x X coordinate
- @param y Y coordinate
- @return
{boolean}
function main() { var result = doubleClickPoint(100, 100); if (result) { logd("Click succeeded"); } else { logd("Click failed"); }}
main();press Long-press by coordinates
- Long-press event
- @param x X coordinate
- @param y Y coordinate
- @param delay Long-press duration in milliseconds
- @return
{bool}true on success, false on failure
function main() { var result = press(100, 100, 5000); if (result) { logd("Long press succeeded"); } else { logd("Long press failed"); }}
main();Multi-touch
multiTouch Multi-touch
- Multi-touch
- Touch parameters: action — generally 0 = down, 1 = up, 2 = move, 3 = pause
- x: X coordinate
- y: Y coordinate
- pointer: Which finger touch point (1, 2, 3, etc.)
- delay: How many milliseconds to delay before executing this action
- @param touch1 Touch point array for finger 1, for example:
[{"action":0,"x":1,"y":1,"pointer":1,"delay":20},{"action":2,"x":1,"y":1,"pointer":1,"delay":20}] - @param touch2 Touch point array for finger 2
- @param touch3 Touch point array for finger 3
- @param touch4 Touch point array for finger 4
- @param touch5 Touch point array for finger 5
- @param timeout Total multi-touch execution timeout in milliseconds
- @return
{boolean}
function main() { // First style: array-based var touch1 = [ {"action": 0, "x": 500, "y": 1200, "pointer": 1, "delay": 1}, {"action": 2, "x": 500, "y": 1100, "pointer": 1, "delay": 20}, {"action": 2, "x": 500, "y": 1000, "pointer": 1, "delay": 20}, {"action": 1, "x": 1, "y": 1, "pointer": 1, "delay": 20} ]
// Second style: chained calls var touch1 = MultiPoint .get() .action(0).x(500).y(1200).pointer(1).delay(1) .next() .action(2).x(500).y(1100).pointer(1).delay(1) .next() .action(2).x(500).y(1000).pointer(1).delay(1) .next() .action(2).x(500).y(900).pointer(1).delay(1) .next() .action(1).x(500).y(800).pointer(1).delay(1); var touch2 = MultiPoint .get() .action(0).x(300).y(1200).pointer(2).delay(1) .next() .action(2).x(300).y(1100).pointer(2).delay(1) .next() .action(2).x(300).y(1000).pointer(2).delay(1) .next() .action(2).x(300).y(900).pointer(2).delay(1) .next() .action(1).x(300).y(800).pointer(2).delay(1); var x = multiTouch(touch1, touch2, null, null, null, 30000); logd("xxs " + x);}
main();Swipe Functions
swipeToPoint Swipe between coordinate points
- Swipe from one coordinate to another
- @param startX Start X coordinate
- @param startY Start Y coordinate
- @param endX End X coordinate
- @param endY End Y coordinate
- @param duration Duration in milliseconds
- @return
{boolean}true if swipe succeeded, false if swipe failed
function main() { var result = swipeToPoint(10, 10, 100, 100, 200); if (result) { logd("Swipe succeeded"); } else { logd("Swipe failed"); }}
main();swipeToPointPressure Swipe between points with pressure
- Swipe from one coordinate to another
- Supported in EC standalone 2.1.0+
- @param startX Start X coordinate
- @param startY Start Y coordinate
- @param endX End X coordinate
- @param endY End Y coordinate
- @param duration Duration in milliseconds
- @param pressure Pressure, between 0 and 1
- @return true if swipe succeeded, false if swipe failed
function main() { var result = swipeToPointPressure(10, 10, 100, 100, 200, 0.2); if (result) { logd("Swipe succeeded"); } else { logd("Swipe failed"); }}
main();Input Data
inputText Input text
- Enter text
- @param content Content
- @param duration Execution time in milliseconds
- @return
{bool}true on success, false on failure
function main() { var result = inputText("My content", 100); if (result) { logd("Yes"); } else { logd("No"); }}
main();ioHIDEvent Simulate keyboard
- Simulate human–machine interaction, such as keyboard input and shortcuts. See key values for details.
- @param eventPageID Human–machine interaction type
- @param eventUsageID Human–machine interaction value
- @param delay Duration; 0.2 is usually sufficient (there may be latency)
- @return
{boolean}
function main() { let x = ioHIDEvent("0x07", "0x11", 0.2) logd(x)
}
main();Screen Orientation
setOrientation Set screen orientation
- Set screen orientation; landscape supports only 90° clockwise rotation
- @param orientation 1 = normal portrait, 2 = 90° clockwise (landscape)
- @return
{boolean}
function main() { let x = setOrientation(1) logd(x)
}
main();getOrientation Get screen orientation
- Get screen orientation
- @return int | 0 = portrait, 1 = landscape (90° clockwise)
function main() { let x = getOrientation() logd(x)}
main();System Key Functions
home Go to home screen
- Go to home screen
- @return
{boolean}
function main() { var result = home(); if (result) { logd("Success"); } else { logd("Failed"); }}
main();homeScreen Force go to home screen
- Force go to home screen
- @return
{boolean}
function main() { var result = homeScreen(); if (result) { logd("Success"); } else { logd("Failed"); }}
main();isLocked Whether screen is locked
- Whether the screen is locked
- @return
{boolean}
function main() { var result = isLocked(); if (result) { logd("Success"); } else { logd("Failed"); }}
main();lockScreen Lock screen
- Lock screen
- @return
{boolean}
function main() { var result = lockScreen(); if (result) { logd("Success"); } else { logd("Failed"); }}
main();unlockScreen Unlock screen
- Unlock screen; the screen must not have a password, etc.
- @return
{boolean}
function main() { var result = unlockScreen(); if (result) { logd("Success"); } else { logd("Failed"); }}
main();appLaunch Launch app
- Launch an app
- @param bundleId App bundle ID
- @param ignoreState 1 = ignore previous open state and open directly; otherwise use ""
- @return
{boolean}true on success
function main() { var result = appLaunch("com.tencent.xin", "1"); logd("result " + result);}
main();appKillByBundleId Kill app by bundle ID
- Kill a process by bundle ID
- @param bundleId App bundle ID
- @param ignoreState 1 = ignore previous open state and kill directly; otherwise use ""
- @return
{boolean}true on success, false on failure
function main() { var result = appKillByBundleId("com.tencent.xin", "1"); if (result) { logd("Success"); } else { logd("Failed"); }}
main();setAgentTimeout Set agent request timeout
- @param envTimeout Automation startup timeout in milliseconds; can be set to 10000–15000
- @param readTimeout Other request timeout in milliseconds; can be set to 2000–5000
- @return
{boolean}true on success
function main() { setAgentTimeout(10000, 3000);}
main();setAgentPort Set agent port
- @param port Port as an integer; must be greater than 1024
- @return
{bool}true on success, false on failure
function main() { setAgentPort(12008);}
main();setComputeMode Set compute mode
- If you do not understand this function or run into issues, use 2 or the default.
- Set compute mode; default is 2
- @param type: 1 = compute in agent, 2 = compute in app
function main() { setComputeMode(2);}
main();Control Center Functions
getCenterTaskInfo Get control center task parameters
- Get task parameter information sent from the control center
- When the control center starts a script, it can configure parameters; use this function to read them in the script
- Requires EC iOS standalone 3.8.0+
- Note: Parameter configuration is required. Read order: per-device config first; if empty, read global config.
- If the returned parameters contain a key like
__from_global__, the value comes from global config - @return
{json}object
function main() { let taskInfo = getCenterTaskInfo(); logd(JSON.stringify(taskInfo)) if (taskInfo) { // Get task parameters let value = taskInfo["valueJson"] // Get a parameter value, e.g. name // let xm = value["name"] logd(JSON.stringify(value)) }}
main();Coordinate Conversion
convertPointToClickable Convert landscape coordinates to portrait click coordinates
- Convert landscape coordinates to clickable portrait coordinates
- See the FAQ for when conversion is needed
- @param x Landscape X coordinate
- @param y Portrait Y coordinate
- @returns
{json}x = converted X, y = converted Y
function main() { let d = convertPointToClickable(100, 300); logd("x {} y {}", d.x, d.y)}
main();