pyautogui

发布于 2022-12-01  486 次阅读


Please refresh the page if equations are not rendered correctly.
---------------------------------------------------------------

import numpy as np
from time import sleep
import pyautogui as gui

t=0.05

def getPosition(button):
    # button: A string which is the name of the target button
    # Return the coordinate of the button
    print("#Please left-click on %s and hold for 1 second" % button)
    while True:
        a = win32api.GetKeyState(0x01)
        # a = 0: no click; a<0: left; a>0: right click;
        if a <0:
            x,y = gui.position()
            print("x%s, y%s = (%d, %d)" % (button, button, x,y))
            break
        sleep(0.01)
    return x, y

##xUpdate, yUpdate = getPosition("Update")
##sleep(1)
##xNext, yNext = getPosition("Next")
##sleep(1)
##xAdd, yAdd = getPosition("Add")
##sleep(1)
##xDragStart, yDragStart  = getPosition("DragStart")
##sleep(1)
##xDragEnd, yDragEnd  = getPosition("DragEnd")
##sleep(1)
##xSelect, ySelect = getPosition("Select")

#Please left-click on Update and hold for 1 second
xUpdate, yUpdate = (1461, 142)
#Please left-click on Next and hold for 1 second
xNext, yNext = (866, 1010)
#Please left-click on Add and hold for 1 second
xAdd, yAdd = (1453, 110)
#Please left-click on DragStart and hold for 1 second
xDragStart, yDragStart = (1405, 289)
#Please left-click on DragEnd and hold for 1 second
xDragEnd, yDragEnd = (1403, 504)
#Please left-click on Select and hold for 1 second
xSelect, ySelect = (1030, 426)

# button for Update
gui.moveTo(xUpdate, yUpdate)
gui.click(clicks=1, interval=0.1)

# button for next slice
gui.moveTo(xNext, yNext)
gui.click(clicks=5, interval = 0.18)
sleep(t)

# button for Add
gui.moveTo(xAdd, yAdd)
gui.click(clicks=1, interval=t)

# drag-scroll bar
gui.moveTo(xDragStart, yDragStart)
gui.dragTo(xDragEnd, yDragEnd, button='left', duration=0.15,)
sleep(t)

# Choose new roi
gui.moveTo(xSelect, ySelect)
gui.click(clicks=1, interval=t)
sleep(t)

### button for Rename
##gui.moveTo(x=1767, y=424)
##gui.click(clicks=1, interval=t)
##gui.moveTo(x=1007, y=297)

# button for Update
gui.moveTo(xUpdate, yUpdate)
gui.click(clicks=1, interval=0.1)

# return to main window
gui.moveTo(x=1175, y=394)
Everything not saved will be lost.
最后更新于 2022-12-01