Touch

Low-level touch commands. Control gesture at every stage

Overview

Note: Low-level touch command only works with Accessibility Service on Android 8+. Android 7 and below must switch to Native Service for the Touch Capability (Access via the "lighting" button in the app)

Read more at Nougat Limitation


    // New Touch class for you to control the touch at a low-level

    // There are 2 mode: single and multi
    // - Single Mode: switch with the single() method. down, move, up method will send command immediately, index is ignored and default to 0. Use to control 1 finger
    // - Multi Mode: switch with multi() method. down, move, up method will queue the commands for each finger. Use dispatch() method to dispatch the queued commands. Use reset() to clear queue

    // Example:

    // - Single:
    Touch.down(Point(200, 300)) //place finger at 200, 300
    wait(20)
    Touch.move(Point(210, 300)) //move it to 210, 300
    wait(1000) //hold at 210, 300 for 1s
    Touch.up() //release the finger

    // - Multi
    Touch.multi()
    Touch.down(Point(200, 300)) //place finger 0 at 200,300
    Touch.down(Point(300, 300), 1) //place finger 1 at 300,300
    Touch.dispatch() //send command
    wait(20)
    Touch.move(Point(300, 400), 1) //move finger 1 to 300,400
    Touch.dispatch()
    wait(20)
    Touch.down(Point(200, 500)) //move finger 0 to 200,500
    Touch.down(Point(300, 500), 1) //move finger 1 to 300,500
    Touch.dispatch()
    wait(1000)
    Touch.up() //release all fingers
    Touch.dispatch()

    // Note:
    // 1. A gesture is comprise of a down, multiple optional move and a single up. Multiple fingers also count as 1 gesture
    // 2. There can only be one gesture on the screen
    // 3. If another gesture is initialized (via down) while the previous gesture is not finished (not up yet) then the previous gesture will be canceled but also the new gesture will be invalidated

    // From 3 points above: 
    // - A gesture must be complete, an invalid down, move, up sequence will do nothing and also cancel whatever commands you've sent
    // - From point 3, hold one finger and another finger tapping will not work (start another down gesture while previous is not finished)

    // This class doesn't work on Android 7 users with Accessibility Service so it's good practice to check for that and warn the user to switch to Native Service
    // Example detect code
    if (Sys.info("dev.sdk") < 26 and Sys.info("dev.touch") == 0)
        Sys.err("Android 7 with Accessibility detected. Please install Native Service and switch the Touch Capability method in the app for this macro to work")

Static Methods
single
static void single()

Switch to Single Mode.

Single Mode: down, move, up method will send command immediately, index is ignored and default to 0. Use to control 1 finger

multi
static void multi()

Switch to Multi Mode.

Multi Mode: down, move, up method will queue the commands for each finger. Use dispatch() method to dispatch the queued commands. Use reset() to clear queue

down
static void down(point: Point, index: number = 0)

Send down command, the finger is held until up() is called

Parameters
point Coordinates to send command
index Index of the finger (0-9)
move
static void move(point: Point, index: number = 0)

Send move command, the finger is moved to point. Can only be called after down()

Parameters
point Coordinates to send command
index Index of the finger (0-9)
up
static void up(index: number = 0)

Send up command, lift the finger. Can only be called after down() or move(). Calling this method in Multi Mode without any arguments will lift all fingers

Parameters
index Index of the finger (0-9)
dispatch
static void dispatch()

Only in Multi Mode. Dispatch all queued touch commands

reset
static void reset()

Only in Multi Mode. Reset the touch commands queue

swipe
static void swipe(swipePoint: SwipePoint)

Helper method to create a smooth swipe. Can only be called after down() and in Single Mode

Parameters
swipePoint Coordinates and speed are used to create swipe path
getBetween
static Point[] getBetween(swipePoint: SwipePoint, point: Point)

Helper method to generate in-between points between two points.

Parameters
swipePoint Coordinates and speed are used to create swipe path
point The end point
Return
Point[] The in-between points

© 2024 - Macrorify by KoK-CODE