Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

AutoPy Python API specifics for debugging

daluu edited this page Jan 3, 2015 · 1 revision

General

From Python script or shell

import autopy

Finding elements/images on screen

# find by image within another image
canvas = autopy.bitmap.Bitmap.open(image_path)
pos = canvas.find_bitmap(elem[,tolerance]) #tolerance is optional parameter, default is 0.0

# find image from desktop screen
pos = autopy.bitmap.capture_screen().find_bitmap(elem[,tolerance]) #tolerance is optional parameter, default is 0.0

if pos is None:
    print 'image not found'
else:
    print 'image located at (%d,%d)' % (pos[0],pos[1])
# if image not found, can try varying tolerance value from 0.0 to 1.0 to see if it helps or not
# more details at https://github.com/msanders/autopy/issues/25

# finding images/elements
result = autopy.bitmap.capture_screen().find_every_bitmap(elem[,tolerance])
result = canvas.find_every_bitmap(elem[,tolerance]) #canvas from previous line of code above
# if result is empty list, not found, else get list of x,y coordinates, one for each element/image found
# can also use .count_of_bitmap(elem[,tolerance]) to check as well. 0 = not found

Element/Image properties

elem = autopy.bitmap.Bitmap.open(image_path)
print 'image dimensions: %d x %d' % elem.width, elem.height

Taking screenshot

autopy.bitmap.capture_screen().save(path_to_save_screenshot_file)

Sending keys

autopy.key.type_string(keys_to_send) # can also send modifiers, etc. See full API docs.

Mouse actions

autopy.mouse.click() # default of left mouse button
autopy.mouse.click(autopy.mouse.RIGHT_BUTTON)
autopy.mouse.toggle(False) # mouse up on left button
autopy.mouse.toggle(True,autopy.mouse.RIGHT_BUTTON) # mouse down right button
autopy.mouse.smooth_move(x,y)
coordinates = autopy.mouse.get_pos() # returns (x,y)

Full AutoPy API docs & examples

https://github.com/msanders/autopy

http://www.autopy.org/documentation/api-reference/index.html

Morty Proxy This is a proxified and sanitized view of the page, visit original site.