使用自动py将光标移动到图像时出现问题

时间:2018-09-30 17:37:27

标签: python-3.x autopy

我正在学习自动复制,所以希望在这里可以找到帮助。 我正在尝试在屏幕上查找图像并将光标移到该图像上。

我写了以下代码:

import autopy
# Take a screenshot of the entire desktop
autopy.bitmap.capture_screen().save('screen.png')

# define a function to search for the image in the screenshot
def find_image_example():
    aid = autopy.bitmap.Bitmap.open('aid.png') # searched image
    screen = autopy.bitmap.Bitmap.open('screen.png') # Desktop screenshot

    pos = screen.find_every_bitmap(aid,0.1) # find the image if any

    if pos:
        print('Found aid at: %s' % str(pos)) # print all found instances
        x = pos[0][0] # x pos
        y = pos[0][1] # y pos
        print(x) # print for debug
        print(y) # print for debug
        autopy.mouse.smooth_move(x,y) # move the cursor to the first image
    else:
        print('no images found!') # print if no images found
# execute the function
find_image_example()

运行代码后,我收到以下错误消息:

    Found aid at: [(405.0, 1000.0), (552.0, 1000.0), (699.0, 1000.0)]
405.0
1000.0
  File "C:/Users/Mortada/PycharmProjects/autopy_tut/main.py", line 22, in <module>
    find_image_example()
  File "C:/Users/Mortada/PycharmProjects/autopy_tut/main.py", line 18, in find_image_example
    autopy.mouse.smooth_move(x,y) # move the cursor to the first image
ValueError: Point out of bounds

我不确定这里出了什么问题:-/我以为我把它弄对了,大声笑!

aid.png

captured screen

0 个答案:

没有答案