python 输入框拖动随意摆放_Python 模拟向四面八方拖动

# _*_ coding:UTF-8 _*_

import win32api

import win32con

import win32gui

from ctypes import *

import time

from PIL import ImageGrab

class MapClass:

def __init__(self):

self.x0 = 500

self.y0 = 500

self.x1 = 500

self.y1 = 500

self.x2 = 0

self.y2 = 0

self.distance = 100

self.SW = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)# 获得屏幕分辨率X轴

self.SH = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)# 获得屏幕分辨率Y轴

def up(self):

self.x2 = self.x1

self.y2 = self.y1 - self.distance

self.drag(self.x1, self.y1, self.x2, self.y2)

def down(self):

self.x2 = self.x1

self.y2 = self.y1 + self.distance

self.drag(self.x1, self.y1, self.x2, self.y2)

def left(self):

self.x2 = self.x1 - self.distance

self.y2 = self.y1

self.drag(self.x1, self.y1, self.x2, self.y2)

def right(self):

self.x2 = self.x1 + self.distance

self.y2 = self.y1

self.drag(self.x1, self.y1, self.x2, self.y2)

def right_up(self):

self.x2 = self.x1 + self.distance

self.y2 = self.y1 - self.distance

self.drag(self.x1, self.y1, self.x2, self.y2)

def right_down(self):

self.x2 = self.x1 + self.distance

self.y2 = self.y1 + self.distance

self.drag(self.x1, self.y1, self.x2, self.y2)

def left_up(self):

self.x2 = self.x1 - self.distance

self.y2 = self.y1 - self.distance

self.drag(self.x1, self.y1, self.x2, self.y2)

def left_down(self):

self.x2 = self.x1 - self.distance

self.y2 = self.y1 + self.distance

self.drag(self.x1, self.y1, self.x2, self.y2)

def comeBack(self):

self.x1=self.x0

self.y1=self.y0

windll.user32.SetCursorPos(self.x0, self.y0)

def drag(self, x, y, x2, y2):# 拖动

self.mouse_absolute(x, y, x2, y2)

self.x1=x2;# 记录到达的点

self.y1=y2

#time.sleep(1)

#screenshots()

#time.sleep(1)

def mouse_absolute(self, x, y, x2, y2):# 模拟拖动

windll.user32.SetCursorPos(x, y)# 鼠标移动到

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)# 左键按下

time.sleep(0.2)

mw = int(x2 * 65535 / self.SW)

mh = int(y2 * 65535 / self.SH)

win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE + win32con.MOUSEEVENTF_MOVE, mw, mh, 0, 0)

time.sleep(0.2)

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

curVersion='v1'# 版本:v1:虚拟机 v2:平板

rootDir='./resources/'+curVersion+'/'# 根目录

# 截屏

def screenshots():

curTime=time.strftime('%Y-%m-%d %H%M%S',time.localtime(time.time()))

img1=ImageGrab.grab()

fileName=rootDir+'/res/'+curTime+'.jpg'

img1.save(fileName)

#img2=cv2.imread(fileName)

#return img2

time.sleep(3)

mapObj=MapClass()

mapObj.up()

mapObj.up()

mapObj.comeBack()

mapObj.down()

mapObj.down()

mapObj.comeBack()

mapObj.left()

mapObj.left()

mapObj.comeBack()

mapObj.right()

mapObj.right()

mapObj.comeBack()

mapObj.right_up()

mapObj.right_up()

mapObj.comeBack()

mapObj.right_down()

mapObj.right_down()

mapObj.comeBack()

mapObj.left_up()

mapObj.left_up()

mapObj.comeBack()

mapObj.left_down()

mapObj.left_down()

mapObj.comeBack()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值