简体   繁体   English

通过完全控制自动将鼠标从 X1、Y1 移动到 X2、Y2

[英]Automate Mouse Movement from X1,Y1 to X2,Y2 with complete control

This is what I'm trying to do:这就是我想要做的:

Move cursor from Start X, Y to Finish X, Y. In between the Start and Finish points, is a Red Square.将 cursor 从起点 X、Y 移动到终点 X、Y。在起点和终点之间,是一个红色方块。

I'm trying to make a program that does this movement while checking for the condition of the red square.我正在尝试制作一个程序来执行此动作,同时检查红色方块的状况。 If it finds a red square in its path, it will terminate the mouse movement.如果它在其路径中发现一个红色方块,它将终止鼠标移动。 So the cursor will be on the red square.所以 cursor 将在红色方块上。

Something... like... This:一些东西......就像......这个:

Move Cursor(x1, y1)
While cursor isn't at finish point:
      Move Cursor(x2, y2)
      if red square:
        break

I do not need the code to detect the red square, but I need to have a method to move the mouse and have a feature that can abruptly terminate the mouse movement.我不需要代码来检测红色方块,但我需要有一个移动鼠标的方法,并有一个可以突然终止鼠标移动的功能。

Any Ideas?有任何想法吗?

Well, Lets Start This:好吧,让我们开始吧:
first, you could use pyinput , its a realiable library I have used so many times to Control mouse and keyboard, read Here: Pyinput首先,您可以使用pyinput ,它是一个我用过很多次来控制鼠标和键盘的可靠库,请阅读此处: Pyinput

Second, look at my line by line detailed Example Below:Your Code will look something like it二、看我的逐行详细示例如下:你的代码会是这样的

from pynput.mouse import Button, Controller # importing the Function
mouse = Controller() # getting the mouse controller
########################################################################## The function you need
def moveCursor( # the Function name is not representable, personally I would have named it GlideMouseUntil()
                x1,y1, #the Start Position. type (int)
                x2,y2, #the End Position. type (int)
                intervals, #How many points on path you want to check. type (int)
                CheckerFunction #this is the function that will check for the red Square, must return True to stop, False means continue. type(func name)
             ):
    mouse.position = (x1,y1) #set the inital mouse position to the start position
    distance_x = x2-x1 #calculate the Horizontal distance between the two points
    distance_y = y2-y1 #calculate the Vertical distance between the two points
    for n in range(0, intervals+1): #for Every point on the line
        if CheckerFunction(): #Run the ckecker function
            break #if it returns True: break from the loop and exit the function , Red square Found !! YaY
        else: #if it returns False
            mouse.move(x1 + n * (distance_x/intervals), y1 + n * (distance_y/intervals)) #Calulate the Next position and go to it
        pass
    pass
##########################################################################
def checkForRedSquare(): # The function that will Check for the red Square, must return True if square is found . false if not
    if SquareIsFound:
        return True
        pass
    else:
        return False
        pass
##########################################################################
moveCursor(10,10,1000,1000, 30,checkForRedSquare) # means check 30 equally distanced point from poosition(10,10) until (1000,1000) if Square is Found in between stop

I am open to Any Questions我愿意接受任何问题
I hope that Helps, good Luck!!我希望有帮助,祝你好运!!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从列表中表达 x1, y1, x2, y2 - How to express x1, y1, x2, y2 from a list 如何将 numpy 数组 [(x1,y1),(x2,y2),(x3,y3),...(xn,yn)] 转换为 [(x1,y1,x1^2,y1^2),(x2 ,y2,x2^2,y2^2),…(xn,yn,xn^2,yn^2)] - How to convert a numpy array [(x1,y1),(x2,y2),(x3,y3),…(xn,yn)] to [(x1,y1,x1^2,y1^2),(x2,y2,x2^2,y2^2),…(xn,yn,xn^2,yn^2)] 使用matplotlib.pyplot [[x1,y1],[x2,y2]]绘制点 - draw points using matplotlib.pyplot [[x1,y1],[x2,y2]] 切片 numpy 数组的多个帧,具有多个 y1:y2, x1:x2 - Slice multiple frame of numpy array with multiple y1:y2, x1:x2 Python中如何将YOLO格式标注转换为x1,y1,x2,y2坐标? - How to convert YOLO format annotations to x1, y1, x2, y2 coordinates in Python? 比较两个numpy数组:(x1,y1)和(x2,y2),以检查元素是否相交 - Comparing two numpy arrays: (x1, y1) and (x2, y2) to check whether elements intersect 如何将 x1、x2、y1、y2 数组转换为矩形顶点数组? - How do I turn x1, x2, y1, y2 array into rectangular vertices array? 将二维数组转换为 [ [ x0 y0 ] [x1 y1] [x2 y2] ] 形式 - Converting 2D array into [ [ x0 y0 ] [x1 y1] [x2 y2] ] form 如何计算x,y坐标的点相对于直线的比例百分比(也有x1,y1,x2,y2) - How to calculate the proportional percentage of a point of an x,y coordinate with respect to a line (also with x1, y1, x2, y2) 如何在Python中缩放一条线的长度并获得相应的坐标((x1,y1),(x2,y2))? - How can I scale the length of a line and obtain the corresponding co-ordinates ((x1, y1), (x2, y2)) in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM