Beispiel #1
0
 def click(self, x, y):
     if (self.device_type == 'emu'):
         win32gui.ShowWindow(self.device_id, win32con.SW_SHOW)
         win32gui.SetForegroundWindow(self.device_id)
         win32api.SetCursorPos([self.device_left + x, self.device_top + y])
         win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
         win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
         time.sleep(0.5)
     elif (self.device_type == 'android'):
         adb.click(x, y)
         time.sleep(0.5)
     return
Beispiel #2
0
    def receive_msg(self):
        self.lock.acquire()

        # for this problem: https://bbs.csdn.net/topics/390973288?page=1
        win32api.keybd_event(0x11, 0, 0, 0)  # ctrl
        win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key

        win32gui.ShowWindow(self.con_hwnd, win32con.SW_MAXIMIZE)
        win32gui.SetForegroundWindow(self.con_hwnd)

        time.sleep(1)

        x_mid = int(win32api.GetSystemMetrics(win32con.SM_CXSCREEN) / 2)
        y_mid = int(win32api.GetSystemMetrics(win32con.SM_CYSCREEN) / 2)
        win32api.SetCursorPos([x_mid, y_mid])

        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0,
                             0)  # left mouse button
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0,
                             0)  # release key

        win32api.keybd_event(0x11, 0, 0, 0)  # ctrl
        win32api.keybd_event(0x41, 0, 0, 0)  # 'a'
        win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key
        win32api.keybd_event(0x41, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key

        win32api.keybd_event(0x11, 0, 0, 0)  # ctrl
        win32api.keybd_event(0x43, 0, 0, 0)  # 'c'
        win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key
        win32api.keybd_event(0x43, 0, win32con.KEYEVENTF_KEYUP,
                             0)  # release key

        time.sleep(1)

        win32clipboard.OpenClipboard()
        text = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)
        win32clipboard.CloseClipboard()

        win32gui.SetForegroundWindow(self.cur_hwnd)

        time.sleep(1)

        self.lock.release()

        return text
Beispiel #3
0
 def click(self, iX, iY):
     iX = int(iX)
     iY = int(iY)
     if (self.oCommandListener.Flag is False):
         flags, hcursor, (x, y) = win32gui.GetCursorInfo()
         if (self.lastPos != (x, y)):
             print("If you want to block mouse moving press SPACE!")
         self.lastPos = (iX, iY)
         win32api.SetCursorPos((iX, iY))
         win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, iX, iY, 0, 0)
         win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, iX, iY, 0, 0)
         win32api.SetCursorPos((x, y))
         print("Mouse click at", iX, iY)
         return True
     else:
         print("Tried to click at", iX, iX)
         return False
Beispiel #4
0
def rclick(x,y):
    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,x,y,0,0)
    time.sleep(0.001)
    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,x,y,0,0)
Beispiel #5
0
def mouse_move(x, y):
    win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, x, y, 0, 0)
Beispiel #6
0
def leftUp():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
    time.sleep(.1)
    print("left release/up")
Beispiel #7
0
def leftDown():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
    time.sleep(.1)
    print("left down")
Beispiel #8
0
def leftClick():
    time.sleep(0.05)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
    time.sleep(.05)
Beispiel #9
0
 def run(self):
     ap = argparse.ArgumentParser()
     ap.add_argument("-p", "--shape-predictor", default='shape_predictor_68_face_landmarks.dat')
     args = vars(ap.parse_args())
     EYE_AR_THRESH = 0.2
     EYE_AR_CONSEC_FRAMES = 2
     COUNTER = 0
     TOTAL = 0

     print("[INFO] loading facial landmark predictor...")
     detector = dlib.get_frontal_face_detector()
     predictor = dlib.shape_predictor(args["shape_predictor"])

     (lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
     (rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
     (uStart, dEnd) = face_utils.FACIAL_LANDMARKS_IDXS["nose"]

     vs = VideoStream(src=0).start()
# vs = VideoStream(usePiCamera=True).start()
     fileStream = False

     #fourcc = cv2.VideoWriter_fourcc(*'DIVX')
     #out = cv2.VideoWriter('output.avi', fourcc, 2.6, (1600, 1000))
     time.sleep(1.0)
     fps = FPS().start()
# loop over frames from the video stream
     while True:
         if fileStream and not vs.more():
             break

         frame = vs.read()
         frame = imutils.resize(frame, width=1800,height=850)
         gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
         rects = detector(gray, 0)
         for rect in rects:
             shape = predictor(gray, rect)
             points = face_utils.shape_to_np(shape)
             leftEye = points[42:48]  # 取出左眼对应的特征点
             rightEye = points[36:42]  # 取出右眼对应的特征点
             leftEAR = self.eye_aspect_ratio(leftEye)
             rightEAR = self.eye_aspect_ratio(rightEye)
             ear = (leftEAR + rightEAR) / 2.0
             x = leftEye[0]
             x1 = 1800 - x[0]
             pyautogui.moveTo(x1, x[1])
             leftEyeHull = cv2.convexHull(leftEye)
             rightEyeHull = cv2.convexHull(rightEye)
             cv2.drawContours(frame, [leftEyeHull], -1, (0, 255, 0), 1)
             cv2.drawContours(frame, [rightEyeHull], -1, (0, 255, 0), 1)
             if ear < EYE_AR_THRESH:
                 COUNTER += 1
                 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
                 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

             if COUNTER >= EYE_AR_CONSEC_FRAMES:
                 TOTAL += 1
                 COUNTER = 0

             cv2.putText(frame, "Blinks: {}".format(TOTAL), (10, 30),
                         cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
             cv2.putText(frame, "EAR: {:.2f}".format(ear), (300, 30),
                         cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
             #frame1 = cv2.resize(frame, (1600, 1000))
             #out.write(frame1)
         cv2.imshow("Frame", frame)
         key = cv2.waitKey(1) & 0xFF

         if key == ord("q"):
             break

     fps.stop()
     print("[INFO] elapsed time: {:.2f}".format(fps.elapsed()))
     print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
     vs.stream.release()
     #out.release()
     cv2.destroyAllWindows()
Beispiel #10
0
def left_click(pos):
    mouse_pos(pos)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
    time.sleep(0.1)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
Beispiel #11
0
def click1(x, y):  #第一种
    win32api.SetCursorPos((x, y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
Beispiel #12
0
print(strBuf)
# 发送消息获取文本内容
# 参数:窗口句柄; 消息类型;文本大小; 存储位置
length = win32gui.SendMessage(subHandle, win32con.WM_GETTEXT, bufSize, strBuf)
# 反向内容,转为字符串
# text = str(strBuf[:-1])

address, length = win32gui.PyGetBufferAddressAndLen(strBuf)
text = win32gui.PyGetString(address, length)
# print('text: ', text)

# 鼠标单击事件
#鼠标定位到(30,50)
win32api.SetCursorPos([30, 150])
#执行左单键击,若需要双击则延时几毫秒再点击一次即可
win32api.mouse_event(
    win32con.MOUSEEVENTF_LEFTUP | win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
#右键单击
win32api.mouse_event(
    win32con.MOUSEEVENTF_RIGHTUP | win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)


def click1(x, y):  #第一种
    win32api.SetCursorPos((x, y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)


def click2(x, y):  #第二种
    ctypes.windll.user32.SetCursorPos(x, y)
    ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0)
    ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0)