Input actions#

Commands that press keys, move and click the mouse, touch, swipe and tilt in your app, as a player would. They are all methods of AltDriver; to tap or click a specific object, see also AltObject.

Each command shows its signature and an example in every language; pick a language in any tab and the others switch with it.

Commands on this page#

Command

What it does

PressKey

Presses a key, holds it for duration seconds, and releases it.

PressKeys

Presses several keys at the same time, holds them for duration seconds, and releases them.

KeyDown

Presses a key and keeps it pressed until KeyUp releases it.

KeyUp

Releases a key pressed with KeyDown.

MoveMouse

Moves the mouse pointer to a position on the screen, over duration seconds.

Click

Clicks at a position on the screen, once or several times.

HoldButton

Presses the left mouse button at a position on the screen, holds it for duration seconds, and releases it.

Scroll

Scrolls the mouse wheel at the pointer’s position, for duration seconds.

Tap

Taps a position on the screen, once or several times.

Swipe

Drags from one position on the screen to another, over duration seconds.

MultipointSwipe

Drags through several positions on the screen in order, over duration seconds.

BeginTouch

Puts a finger on the screen and returns its id.

MoveTouch

Moves a finger put down with BeginTouch to a new position.

EndTouch

Lifts a finger put down with BeginTouch.

Tilt

Tilts the device by applying an acceleration, over duration seconds.

ResetInput

Releases every key, button and touch that AltTester® is still holding, for example after a test that failed between KeyDown and KeyUp.

Keyboard and joystick#

PressKey#

Presses a key, holds it for duration seconds, and releases it.

void PressKey(
    AltKeyCode keyCode,
    float power = 1,
    float duration = 0.1f,
    bool wait = true)

Example

// Jump: hold Space for half a second.
altDriver.PressKey(AltKeyCode.Space, duration: 0.5f);
void pressKey(AltPressKeyParams params)

new AltPressKeyParams.Builder(AltKeyCode keyCode)
    .withPower(float power)  // default 1
    .withDuration(float duration)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Jump: hold Space for half a second.
altDriver.pressKey(new AltPressKeyParams.Builder(AltKeyCode.Space)
        .withDuration(0.5f)
        .build());
alt_driver.press_key(key_code, power=1, duration=0.1, wait=True)

Example

from alttester import AltKeyCode

# Jump: hold Space for half a second.
alt_driver.press_key(AltKeyCode.Space, duration=0.5)
Press Key    key_code    power=1    duration=0.1    wait=True

Example

# Jump: hold Space for half a second.
Press Key    Space    duration=0.5

Parameters

Name

Type

Default

Description

keyCode (C#, Java)
key_code (Python, Robot)

C#, Java, Python: AltKeyCode
Robot: key name, such as Space

required

The key to press.

power

float

1

For joysticks, how hard the key is pressed, from -1 to 1.

duration

float

0.1

Seconds from the key press to the key release.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

See also: PressKeys · KeyDown

PressKeys#

Presses several keys at the same time, holds them for duration seconds, and releases them.

void PressKeys(
    AltKeyCode[] keyCodes,
    float power = 1,
    float duration = 0.1f,
    bool wait = true)

Example

// Run forward: Shift and W together, for one second.
altDriver.PressKeys(new[] { AltKeyCode.LeftShift, AltKeyCode.W }, duration: 1);
void pressKeys(AltPressKeysParams params)

new AltPressKeysParams.Builder(AltKeyCode[] keyCodes)
    .withPower(float power)  // default 1
    .withDuration(float duration)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Run forward: Shift and W together, for one second.
AltKeyCode[] keys = { AltKeyCode.LeftShift, AltKeyCode.W };
altDriver.pressKeys(new AltPressKeysParams.Builder(keys).withDuration(1).build());
alt_driver.press_keys(key_codes, power=1, duration=0.1, wait=True)

Example

from alttester import AltKeyCode

# Run forward: Shift and W together, for one second.
alt_driver.press_keys([AltKeyCode.LeftShift, AltKeyCode.W], duration=1)
Press Keys    key_codes    power=1    duration=0.1    wait=True

Example

# Run forward: Shift and W together, for one second.
${keys}=    Create List    LeftShift    W
Press Keys    ${keys}    duration=1

Parameters

Name

Type

Default

Description

keyCodes (C#, Java)
key_codes (Python, Robot)

C#, Java: AltKeyCode[]
Python: list of AltKeyCode
Robot: list of key names

required

The keys to press together.

power

float

1

For joysticks, how hard the key is pressed, from -1 to 1.

duration

float

0.1

Seconds from the key press to the key release.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

See also: PressKey

KeyDown#

Presses a key and keeps it pressed until KeyUp releases it. Use it for keys a player holds, such as a key that keeps a character moving.

void KeyDown(AltKeyCode keyCode, float power = 1)

Example

// Walk forward for a second, then stop.
altDriver.KeyDown(AltKeyCode.W);
Thread.Sleep(1000);
altDriver.KeyUp(AltKeyCode.W);
void keyDown(AltKeyDownParams params)

new AltKeyDownParams.Builder(AltKeyCode keyCode)
    .withPower(float power)  // default 1
    .build()

Example

// Walk forward for a second, then stop.
altDriver.keyDown(new AltKeyDownParams.Builder(AltKeyCode.W).build());
Thread.sleep(1000);
altDriver.keyUp(new AltKeyUpParams.Builder(AltKeyCode.W).build());
alt_driver.key_down(key_code, power=1)

Example

import time
from alttester import AltKeyCode

# Walk forward for a second, then stop.
alt_driver.key_down(AltKeyCode.W)
time.sleep(1)
alt_driver.key_up(AltKeyCode.W)
Key Down    key_code    power=1

Example

# Walk forward for a second, then stop.
Key Down    W
Sleep    1s
Key Up    W

Parameters

Name

Type

Default

Description

keyCode (C#, Java)
key_code (Python, Robot)

C#, Java, Python: AltKeyCode
Robot: key name, such as Space

required

The key to press.

power

float

1

For joysticks, how hard the key is pressed, from -1 to 1.

Returns

Nothing.

See also: KeyUp · PressKey · ResetInput

KeyUp#

Releases a key pressed with KeyDown.

void KeyUp(AltKeyCode keyCode)

Example

// Walk forward for a second, then stop.
altDriver.KeyDown(AltKeyCode.W);
Thread.Sleep(1000);
altDriver.KeyUp(AltKeyCode.W);
void keyUp(AltKeyUpParams params)

new AltKeyUpParams.Builder(AltKeyCode keyCode)
    .build()

Example

// Walk forward for a second, then stop.
altDriver.keyDown(new AltKeyDownParams.Builder(AltKeyCode.W).build());
Thread.sleep(1000);
altDriver.keyUp(new AltKeyUpParams.Builder(AltKeyCode.W).build());
alt_driver.key_up(key_code)

Example

import time
from alttester import AltKeyCode

# Walk forward for a second, then stop.
alt_driver.key_down(AltKeyCode.W)
time.sleep(1)
alt_driver.key_up(AltKeyCode.W)
Key Up    key_code

Example

# Walk forward for a second, then stop.
Key Down    W
Sleep    1s
Key Up    W

Parameters

Name

Type

Default

Description

keyCode (C#, Java)
key_code (Python, Robot)

C#, Java, Python: AltKeyCode
Robot: key name, such as Space

required

The key to release.

Returns

Nothing.

See also: KeyDown

Mouse#

Coordinates are screen positions in pixels, as returned by an object’s GetScreenPosition.

MoveMouse#

Moves the mouse pointer to a position on the screen, over duration seconds.

void MoveMouse(
    AltVector2 coordinates,
    float duration = 0.1f,
    bool wait = true)

Example

// Hover over the start button, to show its tooltip.
var button = altDriver.FindObject(By.NAME, "StartButton");
altDriver.MoveMouse(button.GetScreenPosition(), duration: 0.5f);
void moveMouse(AltMoveMouseParams params)

new AltMoveMouseParams.Builder(Vector2 coordinates)
    .withDuration(float duration)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Hover over the start button, to show its tooltip.
AltObject button = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "StartButton").build());
altDriver.moveMouse(new AltMoveMouseParams.Builder(button.getScreenPosition())
        .withDuration(0.5f)
        .build());
alt_driver.move_mouse(coordinates, duration=0.1, wait=True)

Example

# Hover over the start button, to show its tooltip.
button = alt_driver.find_object(By.NAME, "StartButton")
alt_driver.move_mouse(button.get_screen_position(), duration=0.5)
Move Mouse    coordinates    duration=0.1    wait=True

Example

# Hover over the start button, to show its tooltip.
${button}=    Find Object    NAME    StartButton
${position}=    Get Screen Position    ${button}
Move Mouse    ${position}    duration=0.5

Parameters

Name

Type

Default

Description

coordinates

C#: AltVector2
Java: Vector2
Python, Robot: list or dict

required

Where to move the pointer, in screen pixels.

duration

float

0.1

Seconds to move from the current position to coordinates.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

See also: Click · Scroll

Click#

Clicks at a position on the screen, once or several times.

void Click(
    AltVector2 coordinates,
    int count = 1,
    float interval = 0.1f,
    bool wait = true)

Example

// Double-click a file in a list.
var file = altDriver.FindObject(By.NAME, "SaveSlot1");
altDriver.Click(file.GetScreenPosition(), count: 2);
void click(AltTapClickCoordinatesParams params)

new AltTapClickCoordinatesParams.Builder(Vector2 coordinates)
    .withCount(int count)  // default 1
    .withInterval(float interval)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Double-click a file in a list.
AltObject file = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "SaveSlot1").build());
altDriver.click(new AltTapClickCoordinatesParams.Builder(file.getScreenPosition())
        .withCount(2)
        .build());
alt_driver.click(coordinates, count=1, interval=0.1, wait=True)

Example

# Double-click a file in a list.
file = alt_driver.find_object(By.NAME, "SaveSlot1")
alt_driver.click(file.get_screen_position(), count=2)
Click    coordinates    count=1    interval=0.1    wait=True

Example

# Double-click a file in a list.
${file}=    Find Object    NAME    SaveSlot1
${position}=    Get Screen Position    ${file}
Click    ${position}    count=2

Parameters

Name

Type

Default

Description

coordinates

C#: AltVector2
Java: Vector2
Python, Robot: list or dict

required

Where to click, in screen pixels.

count

int

1

How many times to click. 2 is a double-click.

interval

float

0.1

Seconds between clicks.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

See also: Tap · HoldButton

HoldButton#

Presses the left mouse button at a position on the screen, holds it for duration seconds, and releases it.

void HoldButton(
    AltVector2 coordinates,
    float duration,
    bool wait = true)

Example

// Long-press an item for two seconds, to open its menu.
var item = altDriver.FindObject(By.NAME, "InventoryItem");
altDriver.HoldButton(item.GetScreenPosition(), 2);
void holdButton(AltHoldParams params)

new AltHoldParams.Builder(Vector2 coordinates)
    .withDuration(float duration)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Long-press an item for two seconds, to open its menu.
AltObject item = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "InventoryItem").build());
altDriver.holdButton(new AltHoldParams.Builder(item.getScreenPosition())
        .withDuration(2)
        .build());
alt_driver.hold_button(coordinates, duration=0.1, wait=True)

Example

# Long-press an item for two seconds, to open its menu.
item = alt_driver.find_object(By.NAME, "InventoryItem")
alt_driver.hold_button(item.get_screen_position(), duration=2)
Hold Button    coordinates    duration=0.1    wait=True

Example

# Long-press an item for two seconds, to open its menu.
${item}=    Find Object    NAME    InventoryItem
${position}=    Get Screen Position    ${item}
Hold Button    ${position}    duration=2

Parameters

Name

Type

Default

Description

coordinates

C#: AltVector2
Java: Vector2
Python, Robot: list or dict

required

Where to press, in screen pixels.

duration

float

required (C#)
0.1 (Java, Python, Robot)

Seconds to hold the button down.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

See also: Click

Scroll#

Scrolls the mouse wheel at the pointer’s position, for duration seconds.

void Scroll(float speed = 1, float duration = 0.1f, bool wait = true)
void Scroll(
    AltVector2 scrollValue,
    float duration = 0.1f,
    bool wait = true)

Example

// Scroll down a list: move the pointer over it first.
var list = altDriver.FindObject(By.NAME, "LevelList");
altDriver.MoveMouse(list.GetScreenPosition());
altDriver.Scroll(-2, duration: 0.5f);
void scroll(AltScrollParams params)

new AltScrollParams.Builder()
    .withSpeed(float speed)  // default 1
    .withDuration(float duration)  // default 0.1f
    .withWait(boolean wait)  // default true
    .withHorizontalSpeed(float speedHorizontal)  // default 1
    .build()

Example

// Scroll down a list: move the pointer over it first.
AltObject list = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "LevelList").build());
altDriver.moveMouse(new AltMoveMouseParams.Builder(list.getScreenPosition()).build());
altDriver.scroll(new AltScrollParams.Builder()
        .withSpeed(-2)
        .withHorizontalSpeed(0)
        .withDuration(0.5f)
        .build());
alt_driver.scroll(
    speed_vertical=1,
    duration=0.1,
    wait=True,
    speed_horizontal=1)

Example

# Scroll down a list: move the pointer over it first.
level_list = alt_driver.find_object(By.NAME, "LevelList")
alt_driver.move_mouse(level_list.get_screen_position())
alt_driver.scroll(speed_vertical=-2, speed_horizontal=0, duration=0.5)
Scroll    speed_vertical=1    duration=0.1    wait=True    speed_horizontal=1

Example

# Scroll down a list: move the pointer over it first.
${list}=    Find Object    NAME    LevelList
${position}=    Get Screen Position    ${list}
Move Mouse    ${position}
Scroll    speed_vertical=-2    speed_horizontal=0    duration=0.5

Parameters

Name

Type

Default

Description

speed (C#, Java)
speed_vertical (Python, Robot)

float

1

How fast to scroll up (positive) or down (negative).

duration

float

0.1

Seconds to scroll for.

wait

bool

true

Wait for the command to finish before returning.

speedHorizontal (Java)
speed_horizontal (Python, Robot)

float

1

How fast to scroll right (positive) or left (negative). Only in Java, Python, Robot.

Returns

Nothing.

Note

In C#, Scroll(speed) scrolls vertically only. To scroll both ways, use Scroll(AltVector2 scrollValue): x is the horizontal speed and y the vertical speed.

In Java, Python and Robot Framework the horizontal speed defaults to 1. Set it to 0 to scroll vertically only.

Move the pointer over what you want to scroll first, with MoveMouse.

See also: MoveMouse

Touch#

Coordinates are screen positions in pixels, as returned by an object’s GetScreenPosition.

Tap#

Taps a position on the screen, once or several times.

void Tap(
    AltVector2 coordinates,
    int count = 1,
    float interval = 0.1f,
    bool wait = true)

Example

// Tap the start button.
var button = altDriver.FindObject(By.NAME, "StartButton");
altDriver.Tap(button.GetScreenPosition());
void tap(AltTapClickCoordinatesParams params)

new AltTapClickCoordinatesParams.Builder(Vector2 coordinates)
    .withCount(int count)  // default 1
    .withInterval(float interval)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Tap the start button.
AltObject button = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "StartButton").build());
altDriver.tap(new AltTapClickCoordinatesParams.Builder(button.getScreenPosition())
        .build());
alt_driver.tap(coordinates, count=1, interval=0.1, wait=True)

Example

# Tap the start button.
button = alt_driver.find_object(By.NAME, "StartButton")
alt_driver.tap(button.get_screen_position())
Tap    coordinates    count=1    interval=0.1    wait=True

Example

# Tap the start button.
${button}=    Find Object    NAME    StartButton
${position}=    Get Screen Position    ${button}
Tap    ${position}

Parameters

Name

Type

Default

Description

coordinates

C#: AltVector2
Java: Vector2
Python, Robot: list or dict

required

Where to tap, in screen pixels.

count

int

1

How many times to tap.

interval

float

0.1

Seconds between taps.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

See also: Click · Swipe

Swipe#

Drags from one position on the screen to another, over duration seconds. For a path through several positions, use MultipointSwipe.

void Swipe(
    AltVector2 start,
    AltVector2 end,
    float duration = 0.1f,
    bool wait = true)

Example

// Drag a card onto a slot.
var card = altDriver.FindObject(By.NAME, "Card");
var slot = altDriver.FindObject(By.NAME, "Slot");
altDriver.Swipe(
    card.GetScreenPosition(), slot.GetScreenPosition(), duration: 0.5f);
void swipe(AltSwipeParams params)

new AltSwipeParams.Builder(Vector2 start, Vector2 end)
    .withDuration(float duration)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Drag a card onto a slot.
AltObject card = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Card").build());
AltObject slot = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Slot").build());
altDriver.swipe(new AltSwipeParams.Builder(card.getScreenPosition(), slot.getScreenPosition())
        .withDuration(0.5f)
        .build());
alt_driver.swipe(start, end, duration=0.1, wait=True)

Example

# Drag a card onto a slot.
card = alt_driver.find_object(By.NAME, "Card")
slot = alt_driver.find_object(By.NAME, "Slot")
alt_driver.swipe(
    card.get_screen_position(), slot.get_screen_position(), duration=0.5)
Swipe    start    end    duration=0.1    wait=True

Example

# Drag a card onto a slot.
${card}=    Find Object    NAME    Card
${slot}=    Find Object    NAME    Slot
${start}=    Get Screen Position    ${card}
${end}=    Get Screen Position    ${slot}
Swipe    ${start}    ${end}    duration=0.5

Parameters

Name

Type

Default

Description

start

C#: AltVector2
Java: Vector2
Python, Robot: list or dict

required

Where the swipe starts, in screen pixels.

end

C#: AltVector2
Java: Vector2
Python, Robot: list or dict

required

Where the swipe ends, in screen pixels.

duration

float

0.1

Seconds to move from start to end.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

See also: MultipointSwipe · BeginTouch · Tap

MultipointSwipe#

Drags through several positions on the screen in order, over duration seconds.

void MultipointSwipe(
    AltVector2[] positions,
    float duration = 0.1f,
    bool wait = true)

Example

// Draw a V shape through three points.
var path = new[]
{
    new AltVector2(100, 300),
    new AltVector2(200, 100),
    new AltVector2(300, 300),
};
altDriver.MultipointSwipe(path, duration: 1);
void multipointSwipe(AltMultiPointSwipeParams params)

new AltMultiPointSwipeParams.Builder(List<Vector2> positions)
    .withDuration(float duration)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Draw a V shape through three points.
List<Vector2> path = Arrays.asList(
        new Vector2(100, 300), new Vector2(200, 100), new Vector2(300, 300));
altDriver.multipointSwipe(new AltMultiPointSwipeParams.Builder(path)
        .withDuration(1)
        .build());
alt_driver.multipoint_swipe(positions, duration=0.1, wait=True)

Example

# Draw a V shape through three points.
alt_driver.multipoint_swipe([[100, 300], [200, 100], [300, 300]], duration=1)
Multipoint Swipe    positions    duration=0.1    wait=True

Example

# Draw a V shape through three points.
${p1}=    Create List    100    300
${p2}=    Create List    200    100
${p3}=    Create List    300    300
${path}=    Create List    ${p1}    ${p2}    ${p3}
Multipoint Swipe    ${path}    duration=1

Parameters

Name

Type

Default

Description

positions

C#: AltVector2[]
Java: List<Vector2>
Python, Robot: list of positions

required

The positions to drag through, in screen pixels.

duration

float

0.1

Seconds to move from the first position to the last.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

See also: Swipe

BeginTouch#

Puts a finger on the screen and returns its id. Move it with MoveTouch and lift it with EndTouch. Use these three when a test needs to control each step of a gesture.

int BeginTouch(AltVector2 screenPosition)

Example

// Drag a card onto a slot, one step at a time.
var card = altDriver.FindObject(By.NAME, "Card");
var slot = altDriver.FindObject(By.NAME, "Slot");
int fingerId = altDriver.BeginTouch(card.GetScreenPosition());
altDriver.MoveTouch(fingerId, slot.GetScreenPosition());
altDriver.EndTouch(fingerId);
int beginTouch(AltBeginTouchParams params)

new AltBeginTouchParams.Builder(Vector2 coordinates)
    .build()

Example

// Drag a card onto a slot, one step at a time.
AltObject card = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Card").build());
AltObject slot = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Slot").build());
int fingerId = altDriver.beginTouch(new AltBeginTouchParams.Builder(card.getScreenPosition())
        .build());
altDriver.moveTouch(new AltMoveTouchParams.Builder(fingerId, slot.getScreenPosition())
        .build());
altDriver.endTouch(new AltEndTouchParams.Builder(fingerId).build());
alt_driver.begin_touch(coordinates)

Example

# Drag a card onto a slot, one step at a time.
card = alt_driver.find_object(By.NAME, "Card")
slot = alt_driver.find_object(By.NAME, "Slot")
finger_id = alt_driver.begin_touch(card.get_screen_position())
alt_driver.move_touch(finger_id, slot.get_screen_position())
alt_driver.end_touch(finger_id)
${finger_id}=    Begin Touch    coordinates

Example

# Drag a card onto a slot, one step at a time.
${card}=    Find Object    NAME    Card
${slot}=    Find Object    NAME    Slot
${start}=    Get Screen Position    ${card}
${end}=    Get Screen Position    ${slot}
${finger_id}=    Begin Touch    ${start}
Move Touch    ${finger_id}    ${end}
End Touch    ${finger_id}

Parameters

Name

Type

Default

Description

screenPosition (C#)
coordinates (Java, Python, Robot)

C#: AltVector2
Java: Vector2
Python, Robot: list or dict

required

Where the finger touches the screen, in screen pixels.

Returns

int: The finger id, to pass to MoveTouch and EndTouch.

See also: MoveTouch · EndTouch · Swipe

MoveTouch#

Moves a finger put down with BeginTouch to a new position.

void MoveTouch(int fingerId, AltVector2 screenPosition)

Example

// Drag a card onto a slot, one step at a time.
var card = altDriver.FindObject(By.NAME, "Card");
var slot = altDriver.FindObject(By.NAME, "Slot");
int fingerId = altDriver.BeginTouch(card.GetScreenPosition());
altDriver.MoveTouch(fingerId, slot.GetScreenPosition());
altDriver.EndTouch(fingerId);
void moveTouch(AltMoveTouchParams params)

new AltMoveTouchParams.Builder(int fingerId, Vector2 coordinates)
    .build()

Example

// Drag a card onto a slot, one step at a time.
AltObject card = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Card").build());
AltObject slot = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Slot").build());
int fingerId = altDriver.beginTouch(new AltBeginTouchParams.Builder(card.getScreenPosition())
        .build());
altDriver.moveTouch(new AltMoveTouchParams.Builder(fingerId, slot.getScreenPosition())
        .build());
altDriver.endTouch(new AltEndTouchParams.Builder(fingerId).build());
alt_driver.move_touch(finger_id, coordinates)

Example

# Drag a card onto a slot, one step at a time.
card = alt_driver.find_object(By.NAME, "Card")
slot = alt_driver.find_object(By.NAME, "Slot")
finger_id = alt_driver.begin_touch(card.get_screen_position())
alt_driver.move_touch(finger_id, slot.get_screen_position())
alt_driver.end_touch(finger_id)
Move Touch    finger_id    coordinates

Example

# Drag a card onto a slot, one step at a time.
${card}=    Find Object    NAME    Card
${slot}=    Find Object    NAME    Slot
${start}=    Get Screen Position    ${card}
${end}=    Get Screen Position    ${slot}
${finger_id}=    Begin Touch    ${start}
Move Touch    ${finger_id}    ${end}
End Touch    ${finger_id}

Parameters

Name

Type

Default

Description

fingerId (C#, Java)
finger_id (Python, Robot)

int

required

The id that BeginTouch returned.

screenPosition (C#)
coordinates (Java, Python, Robot)

C#: AltVector2
Java: Vector2
Python, Robot: list or dict

required

Where to move the finger, in screen pixels.

Returns

Nothing.

See also: BeginTouch · EndTouch

EndTouch#

Lifts a finger put down with BeginTouch. The id can’t be used after this.

void EndTouch(int fingerId)

Example

// Drag a card onto a slot, one step at a time.
var card = altDriver.FindObject(By.NAME, "Card");
var slot = altDriver.FindObject(By.NAME, "Slot");
int fingerId = altDriver.BeginTouch(card.GetScreenPosition());
altDriver.MoveTouch(fingerId, slot.GetScreenPosition());
altDriver.EndTouch(fingerId);
void endTouch(AltEndTouchParams params)

new AltEndTouchParams.Builder(int fingerId)
    .build()

Example

// Drag a card onto a slot, one step at a time.
AltObject card = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Card").build());
AltObject slot = altDriver.findObject(
        new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Slot").build());
int fingerId = altDriver.beginTouch(new AltBeginTouchParams.Builder(card.getScreenPosition())
        .build());
altDriver.moveTouch(new AltMoveTouchParams.Builder(fingerId, slot.getScreenPosition())
        .build());
altDriver.endTouch(new AltEndTouchParams.Builder(fingerId).build());
alt_driver.end_touch(finger_id)

Example

# Drag a card onto a slot, one step at a time.
card = alt_driver.find_object(By.NAME, "Card")
slot = alt_driver.find_object(By.NAME, "Slot")
finger_id = alt_driver.begin_touch(card.get_screen_position())
alt_driver.move_touch(finger_id, slot.get_screen_position())
alt_driver.end_touch(finger_id)
End Touch    finger_id

Example

# Drag a card onto a slot, one step at a time.
${card}=    Find Object    NAME    Card
${slot}=    Find Object    NAME    Slot
${start}=    Get Screen Position    ${card}
${end}=    Get Screen Position    ${slot}
${finger_id}=    Begin Touch    ${start}
Move Touch    ${finger_id}    ${end}
End Touch    ${finger_id}

Parameters

Name

Type

Default

Description

fingerId (C#, Java)
finger_id (Python, Robot)

int

required

The id that BeginTouch returned.

Returns

Nothing.

See also: BeginTouch · MoveTouch

Device#

Tilt#

Tilts the device by applying an acceleration, over duration seconds.

void Tilt(
    AltVector3 acceleration,
    float duration = 0.1f,
    bool wait = true)

Example

// Tilt the device to the right for one second.
altDriver.Tilt(new AltVector3(1, 0, 0), duration: 1);
void tilt(AltTiltParams params)

new AltTiltParams.Builder(Vector3 acceleration)
    .withDuration(float duration)  // default 0.1f
    .withWait(boolean wait)  // default true
    .build()

Example

// Tilt the device to the right for one second.
altDriver.tilt(new AltTiltParams.Builder(new Vector3(1, 0, 0)).withDuration(1).build());
alt_driver.tilt(acceleration, duration=0.1, wait=True)

Example

# Tilt the device to the right for one second.
alt_driver.tilt([1, 0, 0], duration=1)
Tilt    acceleration    duration=0.1    wait=True

Example

# Tilt the device to the right for one second.
${acceleration}=    Create List    1    0    0
Tilt    ${acceleration}    duration=1

Parameters

Name

Type

Default

Description

acceleration

C#: AltVector3
Java: Vector3
Python, Robot: list or dict

required

The linear acceleration of the device on the x, y and z axes.

duration

float

0.1

Seconds the tilt lasts.

wait

bool

true

Wait for the command to finish before returning.

Returns

Nothing.

Resetting input#

ResetInput#

Releases every key, button and touch that AltTester® is still holding, for example after a test that failed between KeyDown and KeyUp.

void ResetInput()

Example

[TearDown]
public void TearDown()
{
    // Release any key or touch that a failed test left pressed.
    altDriver.ResetInput();
}
void resetInput()

Example

@AfterEach
public void tearDown() {
    // Release any key or touch that a failed test left pressed.
    altDriver.resetInput();
}
alt_driver.reset_input()

Example

@pytest.fixture(autouse=True)
def release_input(alt_driver):
    yield
    # Release any key or touch that a failed test left pressed.
    alt_driver.reset_input()
Reset Input

Example

*** Test Cases ***
Walk Forward
    Key Down    W
    Sleep    1s
    Key Up    W
    # Release any key or touch that a failed test left pressed.
    [Teardown]    Reset Input

Returns

Nothing.

See also: KeyDown · BeginTouch