realmouse.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:RunescapeBots 作者: lukegarbutt 项目源码 文件源码
def move_mouse_to(x, y):
    """Function to simulate realistic mouse movements in python. The objective of this
     will be to take in coordinates x,y and move them in a realistic manner. We
     will be passing in an x,y,  that is already 'random' so this function will
     move to the exact x,y"""
    # takes current mouse location and stores it
    while(True):
        try:
            curr_x, curr_y = pyautogui.position()
            # calculates the distance from current position to target position
            distance = int(((x - curr_x)**2 + (y - curr_y)**2)**0.5)
            # calculates a random time to make the move take based on the distance
            duration_of_move = (distance * random.random() / 2000) + 0.5
            # move the mouse to our position and takes the time of our duration just
            # calculated
            pyautogui.moveTo(x, y, duration_of_move, pyautogui.easeInOutQuad)
            #pyautogui.moveTo(x, y, duration_of_move, pyautogui.easeOutElastic)
            break
        except:
            print('paused for 10 seconds')
            time.sleep(10)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号