Skip to content

Mouse

Mouse module for autopylot. This module contains functions for mouse control.

Examples:

>>> from autopylot import mouse
>>> mouse.click(x=100, y=100)
>>> mouse.search(image_path='tests\demo.png')
(23, 17)

The module contains the following functions:

  • click(x, y, button, clicks, absolute): Click at the given coordinates.
  • search(image_path, conf, wait, left_click): Search for an image on the screen and return the coordinates of the top-left corner of the image.
  • move(x, y, absolute): Move the mouse to the given coordinates.
  • drag(x, y, button, absolute): Drag the mouse to the given coordinates.
  • scroll(x, y, distance, absolute): Scroll the mouse wheel.

click(x, y, button='left', clicks=1, absolute=True)

Clicks the mouse at the given co-ordinates.

Parameters:

Name Type Description Default
x int

X co-ordinate.

required
y int

Y co-ordinate.

required
button str

The button to click. Can be "left", "right" or "middle". Possible values: "left", "l", "right", "r", "middle", "m".

'left'
clicks int

Number of times to click the mouse button.

1
absolute bool

Whether the co-ordinates are absolute or relative to the current position.

True

Returns:

Type Description
None

None

Examples:

>>> mouse.click(x=100,y= 100)
>>> mouse.click(x=100,y= 100, button="right")
>>> mouse.click(x=100,y= 100, button="middle")
>>> mouse.click(x=100,y= 100, button="left", clicks=2)
>>> mouse.click(x=100,y= 100, button="left", clicks=2, absolute=False)

drag(x_start, y_start, x_end, y_end, absolute=True)

Drags the mouse from one point to another.

Parameters:

Name Type Description Default
x_start int

x-coordinate of the starting point.

required
y_start int

y-coordinate of the starting point.

required
x_end int

x-coordinate of the ending point.

required
y_end int

y-coordinate of the ending point.

required
absolute bool

Whether the co-ordinates are absolute or relative to the current position.

True

Returns:

Type Description
None

None

Examples:

>>> drag(x1=100, y1=100, x2=200, y2=200)

move(x, y, absolute=True)

Moves the cursor to the given X Y Co-ordinates.

Parameters:

Name Type Description Default
x int

x-coordinate on screen.

required
y int

y-coordinate on screen.

required
absolute bool

Whether the co-ordinates are absolute or relative to the current position.

True

Returns:

Type Description
None

None

Examples:

>>> mouse_move(x=100, y=100)

scroll(x, y, dist, absolute=True)

Scrolls the mouse.

Parameters:

Name Type Description Default
x int

x-coordinate on screen.

required
y int

y-coordinate on screen.

required
absolute bool

Whether the co-ordinates are absolute or relative to the current position.

True

Returns:

Type Description
None

None

Examples:

>>> scroll(x=100, y=100, dist=10) # scroll up
>>> scroll(x=100, y=100, dist=-10) # scroll down

search(image_path, conf=0.9, wait=10, left_click=False)

Searches for the given image and returns the co-ordinates of the image.

Parameters:

Name Type Description Default
image_path str || WindowsPath || list

The path to the image.

required
conf int

The confidence level.

0.9
wait int

The time to wait for the image to appear.

10
left_click bool

Whether to left click on the image.

False

Returns:

Name Type Description
Positions tuple || list

A tuple containing the X and Y co-ordinates of the image.

Examples:

>>> mouse.search(image_path='tests\demo.png')
(23, 17)
>>> mouse.search(image_path='tests\demo.png', wait=20, left_click=True)
>>> mouse.search(image_path=['tests\demo.png', 'tests\demo2.png'])
[(23, 17), (67, 16)]