autopilot.input.Touch

class autopilot.input.Touch

A simple touch driver class.

This class can be used for any touch events that require a single active touch at once. If you want to do complex gestures (including multi-touch gestures), look at the autopilot.gestures module.

static create(preferred_backend='')

Get an instance of the Touch class.

Parameters:preferred_backend

A string containing a hint as to which backend you would like. If left blank, autopilot will pick a suitable backend for you. Specifying a backend will guarantee that either that backend is returned, or an exception is raised.

possible backends are:

  • UInput - Use UInput kernel-level device driver.
Raises:RuntimeError if autopilot cannot instantate any of the possible backends.
Raises:RuntimeError if the preferred_backend is specified and is not one of the possible backends for this device class.
Raises:BackendException if the preferred_backend is set, but that backend could not be instantiated.
pressed

Return True if this touch is currently in use (i.e.- pressed on the ‘screen’).

tap(x, y, press_duration=0.1, time_between_events=0.1)

Click (or ‘tap’) at given x,y coordinates.

Parameters:time_between_events – takes floating point to represent the delay time between subsequent taps. Default value 0.1 represents tenth of a second.
tap_object(object, press_duration=0.1, time_between_events=0.1)

Tap the center point of a given object.

It does this by looking for several attributes, in order. The first attribute found will be used. The attributes used are (in order):

  • globalRect (x,y,w,h)
  • center_x, center_y
  • x, y, w, h
  • Parameters:time_between_events – takes floating point to represent the delay time between subsequent taps. Default value 0.1 represents tenth of a second.
    Raises:ValueError if none of these attributes are found, or if an attribute is of an incorrect type.
    press(x, y)

    Press and hold at the given x,y coordinates.

    move(x, y)

    Move the pointer coords to (x,y).

    Note

    The touch ‘finger’ must be pressed for a call to this method to be successful. (see press for further details on touch presses.)

    Raises:RuntimeError if called and the touch ‘finger’ isn’t pressed.
    release()

    Release a previously pressed finger

    drag(x1, y1, x2, y2, rate=10, time_between_events=0.01)

    Perform a drag gesture.

    The finger will be dragged from the starting point to the ending point with multiple moves. The number of moves, and thus the time that it will take to complete the drag can be altered with the rate parameter.

    Parameters:
    • x1 – The point on the x axis where the drag will start from.
    • y1 – The point on the y axis where the drag will starts from.
    • x2 – The point on the x axis where the drag will end at.
    • y2 – The point on the y axis where the drag will end at.
    • rate – The number of pixels the finger will be moved per iteration. Default is 10 pixels. A higher rate will make the drag faster, and lower rate will make it slower.
    • time_between_events – The number of seconds that the drag will wait between iterations.
    Raises:
    • RuntimeError – if the finger is already pressed.
    • RuntimeError – if no more finger slots are available.