Пример #1
0
def cus_mouse_move_position(rptname):
    print("Click Text Coordinates")
    mouse = Controller()
    mouse.position = (500, 640)
    mouse.press(Button.right)
    #mouse.move(500, 0)
    mouse.release(Button.right)
Пример #2
0
def cus_mouse_click_right(rptname):
    print("Click Image Coordinates")
    mouse = Controller()
    mouse.position = (500, 640)
    #mouse.scroll(200, 300)
    mouse.press(Button.right)
    mouse.release(Button.right)
def gesture_control():
    area_list = []
    v = cv2.VideoCapture(0)
    ges = 1
    while (ges == 1):
        ret, i = v.read()
        j = cv2.cvtColor(i, cv2.COLOR_BGR2GRAY)
        k = i[:, :, 1]
        A = []
        g = cv2.subtract(k, j)
        g = cv2.multiply(g, 5)
        r, g = cv2.threshold(g, 50, 255, 0)
        cnt, _ = cv2.findContours(g, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        #print(len(cnt))
        #print(cnt)
        for i in range(0, len(cnt)):
            area = cv2.contourArea(cnt[i])
            A.append(area)
        if (len(cnt) > 0):
            amax = max(A)
            #print(amax)
            if (len(area_list) == 10):
                del area_list[0]
                if (area_list[8] - area_list[0] > 1000):
                    ms.click(Button.left)
                    ms.release(Button.left)
            if (len(area_list) < 10):
                area_list.append(amax)
            ind = A.index(amax)
            M = cv2.moments(cnt[ind])
            #print(M)
            if (M['m00'] > 0.0):
                cx = int(M['m10'] / M['m00'])
                cy = int(M['m01'] / M['m00'])
                ms = Controller()
                ms.position = (3 * cx, 3 * cy)
                if ms.position[0] in range(
                        1270, 1365) and ms.position[1] in range(675, 687):
                    ges = 0
            else:
                pass
        else:
            pass
        print(area_list)
        #time.sleep(5)

        l = cv2.waitKey(1)
        if (l == ord(' ')):
            cv2.destroyAllWindows()
            break
    v.release()
 def handTracking(self):
     mC = Controller()
     # mB = Button()
     mouseX = -1
     mouseY = -1
     cv2.namedWindow("preview")
     vc = cv2.VideoCapture(0)
     if vc.isOpened():
         rval, frame = vc.read()
     else:
         rval = False
     while rval:
         rval, frame = vc.read()
         # img = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
         # frm = frame[120:400,80:400]
         img = cv2.resize(frame, (180, 120))
         data = []
         data.append(img)
         data = np.array(data)
         data = data.reshape(1, 120, 180, 3)
         data = data / 255
         x = self.model.predict(data)
         xl = self.fromScale(640, x[0][0])
         yl = self.fromScale(480, x[0][1])
         xr = self.fromScale(640, x[0][2])
         yr = self.fromScale(480, x[0][3])
         # print(xl,yl,xr,yr)
         frame = cv2.rectangle(frame, (xl - 50, yl - 20),
                               (xr + 20, yr + 20), (255, 0, 0), 2)
         # frame = cv2.rectangle(frame,(0,0),(40,40),(255,114,36),2)
         if xl > 0 and yl > 0 and xr > xl and yr > yl:
             yl -= 20
             yr += 20
             xl -= 50
             xr += 20
             if yl < 0:
                 yl = 0
             if xl < 0:
                 xl = 0
             if yr >= 480:
                 yr = 479
             if xr >= 640:
                 xr = 639
             dtimg = frame[yl:yr, xl:xr]
             dt = []
             dtimg = cv2.resize(dtimg, (180, 120))
             dt.append(dtimg)
             dt = np.asarray(dt)
             dt = dt.reshape(1, 120, 180, 3)
             dt = dt / 255
             value = np.argmax(self.model_Cat.predict(dt)[0])
             print(value)
             # if self.gesture != value:
             #     self.gesture = value
             #     self.counters = [0,0,0,0,0]
             if value == 5:
                 self.counter = [0, 0, 0, 0, 0]
             if value < 5:
                 self.counters[value] += 1
             if value != 5:
                 i = np.argmax(self.counters)
                 if mouseX != -1 and mouseY != -1:
                     xC = int((xl + xr) / 2)
                     yC = int((yl + yr) / 2)
                     xC = int((xC / 640) * 1920)
                     yC = int((yC / 480) * 1080)
                     difX = 0
                     difY = 0
                     if xC > mouseX:
                         difX = 200
                     if xC < mouseX:
                         difX = -200
                     if yC > mouseY:
                         difY = 200
                     if yC < mouseY:
                         difY = -200
                     mouseX += difX
                     mouseY += difY
                     mC.move(difX, difY)
                 else:
                     xC = int((xl + xr) / 2)
                     yC = int((yl + yr) / 2)
                     pxC = xC / 640
                     pyC = yC / 480
                     mC.position = (500, 500)
                     mouseX = 500
                     mouseY = 500
             # print([np.argmax(self.model_Cat.predict(dt)[0]),np.argmax(self.model_Cat.predict(dt)[0]),np.argmax(self.model_Cat.predict(dt)[0])])
         cv2.imshow("preview", frame)
         key = cv2.waitKey(5)
         if key == 27:
             break
     cv2.destroyWindow("preview")
Пример #5
0
def mousecontroller():
    my_mouse = Controller()
    my_mouse.position = (1000, 200)
# print(abc)
# f = open('demo.txt', 'a')
# for item in abc.index:
#     print(abc[0][item])
#
#     f.write(abc[0][item] + ' --->>> ')
#     f.write('\n')

url = 'instagram.com'
wb.get().open_new_tab('https://instagram.com')

from pynput.mouse import Button, Controller

mouse = Controller()
mouse.position = (1230, 40)
time.sleep(5)
mouse.click(Button.left, 1)
mouse.position = (1170, 360)
time.sleep(5)
mouse.click(Button.left, 3)
time.sleep(1)
keyBoardCopy()
altTab()
# value = input('Enter value')
# keyBoardPaste()
# print(value)



Пример #7
0
def mouse_move_pynput(x,y):
    from pynput.mouse import Button, Controller
    """ Déplace la souris vers un couple de coordonnées donné
    """
    mouse = Controller()
    mouse.position = (x,y)