autopilot.input.Mouse

class autopilot.input.Mouse

A simple mouse device class.

The mouse class is used to generate mouse events while in an autopilot test. This class should not be instantiated directly however. To get an instance of the mouse class, call create instead.

For example, to create a mouse object and click at (100,50):

mouse = Mouse.create()
mouse.move(100, 50)
mouse.click()
static create(preferred_backend='')

Get an instance of the Mouse class.

For more infomration on picking specific backends, see Advanced Backend Picking

Parameters:preferred_backend

A string containing a hint as to which backend you would like. Possible backends are:

  • X11 - Generate mouse events using the X11 client libraries.
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.
x

Mouse position X coordinate.

y

Mouse position Y coordinate.

press(button=1)

Press mouse button at current mouse location.

release(button=1)

Releases mouse button at current mouse location.

click(button=1, press_duration=0.1, time_between_events=0.1)

Click mouse at current location.

Parameters:time_between_events – takes floating point to represent the delay time between subsequent clicks. Default value 0.1 represents tenth of a second.
click_object(object_proxy, button=1, press_duration=0.1, time_between_events=0.1)

Click 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 clicks. 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.
    move(x, y, animate=True, rate=10, time_between_events=0.01)

    Moves mouse to location (x,y).

    Callers should avoid specifying the rate or time_between_events parameters unless they need a specific rate of movement.

    move_to_object(object_proxy)

    Attempts to move the mouse to ‘object_proxy’s centre point.

    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
  • Raises:ValueError if none of these attributes are found, or if an attribute is of an incorrect type.
    position()

    Returns the current position of the mouse pointer.

    Returns:(x,y) tuple
    drag(x1, y1, x2, y2, rate=10, time_between_events=0.01)

    Perform a press, move and release.

    This is to keep a common API between Mouse and Finger as long as possible.

    The pointer 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 mouse 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.
    on_test_end(*args)
    on_test_start(*args)