zoukankan      html  css  js  c++  java
  • 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()
    
    
    
    
    
    
    
    
    
  • 相关阅读:
    Linux驱动下的platform总线架构(转)
    一生中很值得看的30个故事之一断箭
    学习嵌入式LINUX系统的笔记和体会
    DIY:自己动手做一个迷你 Linux 系统
    linux里面i386 i686 i486 i586代表什么?是什么意思
    菜鸟编译Linux内核
    LINUX核心重编与升级
    ARM 内核移植中常见的错误
    Linux 2.6.19.x 内核编译配置选项简介
    基于S3C2410平台移植Linux 2.6内核指南
  • 原文地址:https://www.cnblogs.com/guxingy/p/12564631.html
Copyright © 2011-2022 走看看