鼠标 非匀速 拖动

直接把以下代码复制粘贴到自定义函数中即可运行:

# coding=utf-8
import random
from ubpa.iconstant import *
import ubpa.base_native_ait as nit

def mouse_unrule_moveto(x1,y1,x2,y2,point=2,pause=500):

str_xy = get_random_num(x1, x2, y2, point)

msg = move_to_move_pack_au3(x1,y1,str_xy,pause)  # 拼接生成.au3文件用的字符串

tmp_au3_file_path = nit.gen_au3_file(msg)  # 生成.au3文件返回地址

nit.run_autoit(tmp_au3_file_path)  # python执行脚本文件

nit.cleanup(tmp_au3_file_path)  # 清除.au3文件

def move_to_move_pack_au3(x1,y1,str_xy,pause):

str_xy_list = str_xy.split(",")
pre_msg = "#include <AutoItConstants.au3>" \
		  + '\n' + "MouseMove(" + str(x1) + "," + str(y1) + ")" \
		  + '\n' + "Opt('MouseClickDownDelay', 50000)" \
		  + '\n' + "MouseDown($MOUSE_CLICK_LEFT)"
for index in str_xy_list:
    pos = index.split(".")
    x = pos[0]
    y = pos[1]
    pre_msg = pre_msg + '\n' + "MouseMove(" + x + "," + y + ")" \
			  + '\n' + "Sleep(" + str(pause) + ")"

pre_msg = pre_msg + '\n' + "MouseUp($MOUSE_CLICK_LEFT)"

return pre_msg

def get_random_num(x1,x2,y2,point=2):

str_xy = ""
if x1 <= x2:
    num = x1
    for i in range(1,point):

        num = random.randint(num,x2)
        str_xy = str_xy + str(num) + "." + str(y2) + ","

    str_xy = str_xy + str(x2) + "." + str(y2)
else:
    pass

print(str_xy)
return str_xy

以下是新增自定义函数实例:点击编译,运行即可
鼠标 非匀速 拖动