Runtime V2 Reference

Introduction to CogniTab Script Runtime

CogniTab Runtime V2 provides an intuitive Python-based scripting engine for touch automation, image recognition, color detection, and Android screen interaction.

Runtime v2.81September 30, 2026

Quick Start Example

An automation script combining touch gestures, region-based template matching, and multi-point swipe gestures:

Python
# Initialize coordinates and perform basic touch
target = Point(540, 960)
click(target)
wait(400)

# Search for a button image inside a region
search = Region(100, 200, 400, 600)
match = search.find("start_btn", timeout=3000)
if match.found:
    click(match)
    wait(250)
else:
    # Swipe up if element is not yet visible
    swipe([SwipePoint(Point(500, 1200), speed="NORMAL"), SwipePoint(Point(500, 400))])

Best Practice: Multi-Target Image Search with ScreenCapture

When searching for multiple templates or colors in the same frame, calling find() repeatedly causes redundant screen captures. Use ScreenCapture.cache_on() to pin the frame, perform all your searches, and call ScreenCapture.cache_off() afterward. Always remember to turn off cache when you need real-time screen recognition:

Python
# 1. Pin the current frame to optimize multi-image searches
ScreenCapture.cache_on()

area = Region(100, 200, 400, 600)
hit_a = area.find("btn_confirm", timeout=0)
hit_b = area.find("btn_cancel", timeout=0)
hit_c = area.find("icon_close", timeout=0)

# 2. Always turn off cache when you need real-time screen recognition
ScreenCapture.cache_off()

if hit_a.found:
    click(hit_a)
elif hit_b.found:
    click(hit_b)

Basic Python Syntax for Scripts

1. Variable Declaration

Store numbers, strings, booleans, and None values with standard Python syntax.

Python
# Basic variable assignment
count = 3
title = "Farm run"
enabled = True
nothing = None

2. Function Definition (def)

Use def and return to structure reusable logic. Functions can be called before or after their def statement in the same script.

Python
def add(a, b):
    return a + b

def cell(index):
    return index // 9, index % 9

result = add(2, 3)
row, col = cell(10)

3. Global Variables & Closures

Use the global keyword to modify outer variables from within functions; nested functions automatically capture parent scope.

Python
counter = 0

def increment():
    global counter
    counter += 1
    return counter

4. Conditionals & Loops

Control execution flow using if/elif/else, while loops, and for loops with range.

Python
energy = 3
if energy > 0:
    click(Point(500, 900))

for step in range(3):
    wait(200)

5. Core Built-in Classes

Interact with the screen using pre-built classes such as Point, Region, Template, Touch, Color, and ScreenCapture.

Python
target = Point(500, 900)
search_area = Region(100, 200, 300, 400)

click(target)
match = search_area.find("enemy", 2500)
if match.found:
    click(match)

6. Collection Comprehensions

Concise syntax for creating lists, dictionaries, and sets using for/if clauses.

Python
numbers = [1, 2, 3, 4, 5]
evens = [x for x in numbers if x % 2 == 0]
squares = {x: x * x for x in numbers}

Explore the API Catalog

Browse full reference guides for classes, read-only system classes, collections, and gesture functions.