Touch

Manage parallel clicks and swipes from scripts or macro actions: group them, inspect their progress, wait or cancel. In scripts, use click(..., parallel=True) or swipe(..., parallel=True). Sending gestures requires CogniTab's Accessibility service to be enabled.

Syntax

Touch

This class cannot be constructed directly.

Returns

—

Example

Touch.collect()
a = click(Point(300, 900), hold_ms=5000, parallel=True)
b = click(Point(780, 900), hold_ms=1000, delay_before=1000, parallel=True)
sent = Touch.send()
Touch.cancel(a)
Touch.wait()

Methods

7 methods

Touch.collect

Hold subsequent script clicks/swipes with parallel=True until Touch.send(), so they can run together. Other calls are unaffected. Without collection, parallel calls are submitted immediately. Call Touch.send() before the script ends or unsent gestures cause an error.

Syntax

Touch.collect()

Returns

None

Example

# Inspect or control collected touches
Touch.collect()
first = click((300, 900), hold_ms=1000, parallel=True)
second = click((780, 900), delay_before=300, parallel=True)
Touch.send()
Touch.wait()

Touch.send

Submit the collected gestures together and end collection. Returns their numeric IDs in collection order, or an empty list if none were collected. More than 10 gestures raises an error. Submission does not wait for completion; use Touch.wait().

Syntax

Touch.send()

Returns

list[Number]

Example

# Inspect or control collected touches
Touch.collect()
first = click((300, 900), hold_ms=1000, parallel=True)
second = click((780, 900), delay_before=300, parallel=True)
Touch.send()
Touch.wait()

Touch.queued

Return states of submitted gestures waiting to start. Gestures held by Touch.collect() are not included until Touch.send().

Syntax

Touch.queued()

Returns

Example

# Inspect or control collected touches
Touch.collect()
first = click((300, 900), hold_ms=1000, parallel=True)
second = click((780, 900), delay_before=300, parallel=True)
Touch.send()
print(Touch.queued())
Touch.wait()

Touch.active

Return states of gestures currently running.

Syntax

Touch.active()

Returns

Example

# Inspect or control collected touches
Touch.collect()
first = click((300, 900), hold_ms=1000, parallel=True)
second = click((780, 900), delay_before=300, parallel=True)
Touch.send()
print(Touch.active())
Touch.wait()

Touch.all

Return queued and active gesture states plus up to 64 recently finished states. Gestures not yet sent by Touch.send() are excluded.

Syntax

Touch.all()

Returns

Example

# Inspect or control collected touches
Touch.collect()
first = click((300, 900), hold_ms=1000, parallel=True)
second = click((780, 900), delay_before=300, parallel=True)
Touch.send()
print(Touch.all())
Touch.wait()

Touch.wait

Wait for the submitted gesture with this numeric ID and return its TouchState, or None if the ID is unknown or no longer retained. With id=None, wait for all queued/active gestures and return the retained states, including recent finished gestures. Send collected gestures first.

Syntax

Touch.wait(id=None)

Returns

Example

# Inspect or control collected touches
Touch.collect()
first = click((300, 900), hold_ms=1000, parallel=True)
second = click((780, 900), delay_before=300, parallel=True)
Touch.send()
Touch.wait(first)
Touch.wait()

Touch.cancel

Cancel a submitted queued/active gesture by numeric ID; return True if accepted, otherwise False. With id=None, cancel all queued/active gestures and return the accepted count. Cancelling an active gesture requires Android 8.0+ and raises an error on Android 7.x. Does not cancel gestures still held by Touch.collect().

Syntax

Touch.cancel(id=None)

Returns

Boolean | Int

Example

# Inspect or control collected touches
Touch.collect()
first = click((300, 900), hold_ms=1000, parallel=True)
second = click((780, 900), delay_before=300, parallel=True)
Touch.send()
# Active cancellation requires Android 8 or newer
Touch.cancel(second)
Touch.wait()