Пример #1
0
def mouse_click_on_point(x_position, y_position):
    """moves the mouse corsair to the wanted position and clicking on it

    :param x_position: x position
    :param y_position: y position
    :return:
    """
    mouse = Controller()

    # Read pointer position
    print('The current pointer position is {0}'.format(mouse.position))

    # Set pointer position
    mouse.position = (x_position, y_position)
    print('Now we have moved it to {0}'.format(mouse.position))

    # Move pointer relative to current position
    mouse.move(5, -5)

    # Press and release
    mouse.press(Button.left)
    mouse.release(Button.left)

    # Double click; this is different from pressing and releasing
    # twice on Mac OSX
    mouse.click(Button.left, 2)

    # Scroll two steps down
    mouse.scroll(0, 2)
Пример #2
0
 def run(self):
     while self.execute_count > 0:
         with open(self.file_name, 'r', encoding='utf-8') as file:
             mouse_exec = MouseController()
             line = file.readline()
             while line:
                 obj = json.loads(line)
                 if obj['name'] == 'mouse':
                     if obj['event'] == 'move':
                         mouse_exec.position = (obj['location']['x'], obj['location']['y'])
                         time.sleep(0.01)
                     elif obj['event'] == 'click':
                         if obj['action']:
                             if obj['target'] == 'left':
                                 mouse_exec.press(Button.left)
                             else:
                                 mouse_exec.press(Button.right)
                         else:
                             if obj['target'] == 'left':
                                 mouse_exec.release(Button.left)
                             else:
                                 mouse_exec.release(Button.right)
                         time.sleep(0.01)
                     elif obj['event'] == 'scroll':
                         mouse_exec.scroll(obj['location']['x'], obj['location']['y'])
                         time.sleep(0.01)
                 line = file.readline()
Пример #3
0
def scroll(val, up=1):
    #Uses pynput library instead of pyautogui because of better
    #support
    from pynput.mouse import Controller
    mouse = Controller()
    for _ in range(int(val)):
        delay(1 / val)
        mouse.scroll(0, 1 if not up else -1)
def scroll_down():
    """Method that simulates mouse scroll"""
    # Initializing controller
    mouse = Controller()
    # Go to location
    mouse.position = (250, 750)
    # Scroll by 3000 px
    mouse.scroll(0, -3000)
Пример #5
0
class Finger():

    def __init__(self, speed=10):
        self._mse = MouseControl()
        self._kbd = KbdControl()
        self._speed = speed

    def type(self, keys):
        self._kbd.type(keys)

    def move(self, dx, dy, type_='abs'):

        if type_ == 'abs':
            self._mse.position = (dx, dy)

        else:
            self._mse.move(dx, dy)

    def click(self, button='left', count=1):
        button = getattr(Button, button, 'left')
        self._mse.click(button, count)

    def scroll(self, vscr=2, hscr=0):
        self._mse.scroll(hscr, vscr)

    def drag(self, to=(), frm=(), button='left'):
        # simulate a drag. TODO: make in increments instead of instant
        if not frm: frm = self._mse.position
        if not to: to = self._mse.position
        button = getattr(Button, button, 'left')
        self._mse.press(button)
        self._mse.position = to
        self._mse.release(button)

        #while not self._mse.position == to:
            # simulate movement one step at a time
            #x_pos = self._mse.position[0]
            #y_pos = self._mse.position[1]
            #if not x_pos == to[0]: x_pos

    def press(self, device='mouse', button='left'):

        if device == 'mouse':
            self._mse.press(getattr(Button, button, 'left'))

        else:
            key = button if len(button) == 1 else getattr(Key, button, 'space')
            self._kbd.press(key)

    def release(self, device='mouse', button='left'):
        # specify mouse or keyboard

        if device == 'mouse':
            self._mse.release(getattr(Button, button, 'left'))

        else:
            key = button if len(button) == 1 else getattr(Key, button, 'space')
            self._kbd.release(key)
Пример #6
0
    def listen_loop(self, responses):
        mouse = Controller()
        num_chars_printed = 0
        for response in responses:
            if not response.results:
                continue

            result = response.results[0]
            if not result.alternatives:
                continue

            transcript = result.alternatives[0].transcript

            overwrite_chars = " " * (num_chars_printed - len(transcript))

            if not result.is_final:
                # sys.stdout.write(transcript + overwrite_chars + "\r")
                # sys.stdout.flush()

                num_chars_printed = len(transcript)

            else:
                #Final Transcription here
                print(transcript + overwrite_chars)

                # Exit recognition if any of the transcribed phrases could be
                # one of our keywords.
                if re.search(r"\b(press)\b", transcript, re.I):
                    print("Clicking..")
                    mouse.click(Button.left, 1)

                if re.search(r"\b(right click)\b", transcript, re.I):
                    print("Right Clicking..")
                    mouse.click(Button.right, 1)

                if re.search(r"\b(double click)\b", transcript, re.I):
                    print("Double Clicking..")
                    mouse.click(Button.left, 2)

                if re.search(r"\b(scroll up)\b", transcript, re.I):
                    print("Scrolling up..")
                    mouse.scroll(0, 15)

                if re.search(r"\b(scroll down)\b", transcript, re.I):
                    print("Scrolling down..")
                    mouse.scroll(0, -15)

                if re.search(r"\b(start keyboard)\b", transcript, re.I):
                    print("Typing..")
                    self.listen_loop_keyboard(responses)

                if re.search(r"\b(exit|quit)\b", transcript, re.I):
                    print("Exiting..")
                    break

                num_chars_printed = 0
Пример #7
0
def setAngle():
    print('setZoom()')
    click(blueStacksTopLeftCorner[0] + 900 + random.randrange(10),
          blueStacksTopLeftCorner[1] + 60 + random.randrange(10))
    sleep(1)
    moveTo(blueStacksTopLeftCorner[0] + 700 + random.randrange(10),
           blueStacksTopLeftCorner[1] + 500 + random.randrange(10))
    mouse = Controller()
    for i in range(10):
        sleep(0.5)
        mouse.scroll(0, 1)
Пример #8
0
 def movement(
     self
 ):  #function for movements of mouse so that its cant detect its a bot
     mouse = Controller()
     mouse.position = (10, 20)
     mouse.move(60, -150)
     mouse.move(20, -17)
     mouse.move(30, -40)
     mouse.scroll(0, 2)
     mouse.scroll(0, -100)
     mouse.scroll(0, -120)
Пример #9
0
def keystroke_action(inject):
  keyboard = KeyboardController()
  mouse = MouseController()

  for command in inject:
    command = command.split(' ')
    c_type, c_data = command[0], command[1]

    if c_type == 'press': 
      try:
        c_data = eval(f'Key.{c_data}')
      except:
        pass
      finally:
        keyboard.press(c_data)
        keyboard.release(c_data)
    elif c_type == 'hold':
      try:
        c_data = eval(f'Key.{c_data}')
      except:
        pass
      finally:
        keyboard.press(c_data)
    elif c_type == 'release':
      try:
        c_data = eval(f'Key.{c_data}')
      except:
        pass
      finally:
        keyboard.release(c_data)
    elif c_type == 'type':
      keyboard.type(' '.join(command[1:]))
    elif c_type == 'position':
      mouse.position = [int(position) for position in c_data.split(',')]
    elif c_type == 'move':
      move_positions = [int(position) for position in c_data.split(',')]
      mouse.move(move_positions[0], move_positions[1])
    elif c_type == 'mhold':
      mouse.press(eval(f'Button.{c_data}'))
    elif c_type == 'mrelease':
      mouse.release(eval(f'Button.{c_data}'))
    elif c_type == 'click':
      mouse.press(eval(f'Button.{c_data}'))
      mouse.release(eval(f'Button.{c_data}'))
    elif c_type == 'dclick':
      mouse.click(eval(f'Button.{c_data}'), 2)
    elif c_type == 'scroll':
      scroll_positions = [int(position) for position in c_data.split(',')]
      mouse.scroll(scroll_positions[0], scroll_positions[1])
    elif c_type == 'sleep':
      time.sleep(float(c_data))
    else:
      raise Exception('Invalid keystroke command')
Пример #10
0
class Mouse:
    def __init__(self):
        self.mouse = Controller()
        seed(datetime.now())

    def simulateClick(self, clickInfo):
        clickInfo = self.pixelToMouse(clickInfo)
        self.moveAndClick(clickInfo)

    def simulateScroll(self, scrollInfo):
        scrollInfo = (
            self.pixelToMouse(scrollInfo[0]),
            self.pixelToMouse(scrollInfo[1]),
        )
        self.moveAndScroll(scrollInfo)

    def pixelToMouse(self, clickInfo):
        x = SIMULATOR_WINDOW_POSITION_MOUSE[0] + IMG_RESOLUTION_MOUSE[0] * (
            clickInfo[0] / IMG_RESOLUTION[0])
        y = SIMULATOR_WINDOW_POSITION_MOUSE[1] + IMG_RESOLUTION_MOUSE[1] * (
            clickInfo[1] / IMG_RESOLUTION[1])
        z = clickInfo[2] * (IMG_RESOLUTION_MOUSE[0] / IMG_RESOLUTION[0])
        return (int(x), int(y), int(z))

    def moveAndClick(self, clickInfo):
        position = self.generateClickPosition(clickInfo)
        self.mouse.position = position
        sleep(MOVE_CLICK_INTERVAL)
        self.mouse.press(Button.left)
        self.mouse.release(Button.left)

    def moveAndScroll(self, scrollInfo):
        startPosition = self.generateClickPosition(scrollInfo[0])
        endPosition = self.generateClickPosition(scrollInfo[1])
        deltaX = endPosition[0] - startPosition[0]
        deltaY = endPosition[1] - startPosition[1]
        self.mouse.position = startPosition
        sleep(MOVE_CLICK_INTERVAL)
        self.mouse.press(Button.left)
        sleep(MOVE_CLICK_INTERVAL)
        self.mouse.release(Button.left)
        for _ in range(10):
            sleep(MOVE_CLICK_INTERVAL)
            self.mouse.scroll(0, -10)

    def generateClickPosition(self, clickInfo):
        nosie1 = gauss(0, clickInfo[2])
        nosie2 = gauss(0, clickInfo[2])
        position = (clickInfo[0] + nosie1, clickInfo[1] + nosie2)
        return position
Пример #11
0
    def auto_roll(self, area):  # 自动滚动模式
        x, y, w, h = area
        self.rollermask.tips.setText("单击停止")
        QApplication.processEvents()
        speed = round(1 / self.roll_speed, 2)
        screen = QApplication.primaryScreen()
        winid = QApplication.desktop().winId()

        def onclick(x, y, button, pressed):  # 点击退出的函数句柄
            if pressed:
                print("click to stop")
                self.in_rolling = False
                listener.stop()

        controler = MouseController()  # 鼠标控制器
        listener = MouseListenner(on_click=onclick)  # 鼠标监听器
        self.match_thread = Commen_Thread(
            self.match_and_merge)  # 把match_and_merge放入一个线程中
        self.in_rolling = True
        i = 0
        controler.position = (area[0] + int(area[2] / 2),
                              area[1] + int(area[3] / 2))  # 控制鼠标点击到滚动区域中心
        oldimg = Image.new("RGB", (128, 128), "#FF0f00")
        listener.start()
        while self.in_rolling:
            st = time.time()
            pix = screen.grabWindow(winid, x, y, w, h)  # 截屏
            newimg = Image.fromqpixmap(pix)  # 转化为pil的格式
            img = cv2.cvtColor(asarray(newimg), cv2.COLOR_RGB2BGR)
            self.img_list.append(img)  # 图片数据存入self.img_list中被后台的拼接线程使用

            # cv2.imshow("FSd", img)
            # cv2.waitKey(0)
            if i >= 1:
                if i == 1:
                    self.match_thread.start()  # 当截第二张图片时拼接线程才启动
                if self.is_same(oldimg, newimg):  # 每帧检查是否停止
                    self.in_rolling = False
                    i += 1
                    break
            oldimg = newimg
            controler.scroll(dx=0, dy=-3)  # 控制鼠标滚动
            time.sleep(speed)  # 通过sleep控制自动滚动速度
            # cv2.imwrite('j_temp/{0}.png'.format(i), img)
            i += 1
        print("结束滚动,共截屏{}张".format(i))
        listener.stop()
        # self.showrect.hide()
        self.match_thread.wait()
Пример #12
0
    def auto_roll(self, area):
        x, y, w, h = area
        self.tips.setText("单击停止")
        QApplication.processEvents()
        speed = round(1 / self.roll_speed, 2)
        screen = QApplication.primaryScreen()
        winid = QApplication.desktop().winId()

        def onclick(x, y, button, pressed):
            if pressed:
                print("click to stop")
                self.in_rolling = False
                listener.stop()

        controler = MouseController()
        listener = MouseListenner(on_click=onclick)
        self.match_thread = Commen_Thread(self.match_and_merge)
        self.in_rolling = True
        i = 0
        controler.position = (area[0] + int(area[2] / 2), area[1] + int(area[3] / 2))
        oldimg = Image.new("RGB", (128, 128), "#FF0f00")
        listener.start()
        while self.in_rolling:
            st = time.time()
            pix = screen.grabWindow(winid, x, y, w, h)
            newimg = Image.fromqpixmap(pix)
            img = cv2.cvtColor(np.asarray(newimg), cv2.COLOR_RGB2BGR)
            self.img_list.append(img)

            # cv2.imshow("FSd", img)
            # cv2.waitKey(0)
            if i >= 1:
                if i == 1:
                    self.match_thread.start()
                if self.is_same(oldimg, newimg):  # 每帧检查是否停止
                    self.in_rolling = False
                    i += 1
                    break
            oldimg = newimg
            controler.scroll(dx=0, dy=-3)
            time.sleep(speed)
            # cv2.imwrite('j_temp/{0}.png'.format(i), img)
            i += 1
        print("结束滚动,共截屏{}张".format(i))
        listener.stop()
        self.showrect.hide()
        self.match_thread.wait()
        self.showm_signal.emit("长截图完成")
Пример #13
0
    def run(self):
        if not os.path.exists(self.file_name):
            os.mkdir(self.file_name)
        with open(self.file_name, 'r', encoding='utf-8') as file:
            mouse_exec = MouseController()
            line = file.readline()
            # if not line:
            #     print('no mouse')
            #     return
            while line:
                obj = json.loads(line)
                # print(obj)
                if obj['name'] == 'mouse':
                    delay = obj['time'] / self.speed
                    if delay < 0.1:
                        high_precision_delay(delay)
                    elif 1 > delay > 0.1:
                        time.sleep(delay)
                    else:
                        self.listening_sleep(delay)

                    if obj['event'] == 'move':
                        mouse_exec.position = (obj['location']['x'],
                                               obj['location']['y'])
                        # print(1)
                    elif obj['event'] == 'click':
                        if obj['action']:
                            # time.sleep(obj['time'])
                            if obj['target'] == 'left':
                                mouse_exec.press(Button.left)
                            else:
                                mouse_exec.press(Button.right)
                        else:
                            if obj['target'] == 'left':
                                mouse_exec.release(Button.left)
                            else:
                                mouse_exec.release(Button.right)
                    elif obj['event'] == 'scroll':
                        # time.sleep(obj['time'])
                        mouse_exec.scroll(20, obj['location']['y'])
                    if self.stoper:
                        print('鼠标stoper')
                        self.stoper = False
                        break
                line = file.readline()
Пример #14
0
def playScript(waitingTime, type, action, details):
    eventCount = 0
    mouse = MouseController()
    keyboard = KeyController()
    for t in waitingTime:
        time.sleep(int(t) / 1000)
        if type[eventCount] == 'Mouse':
            if action[eventCount] == 'Scrolled':
                # Move mouse to the right position
                arguments = details[eventCount].split(" ", 1)
                coordinates = arguments[0].split(",", 1)
                xpos = coordinates[0][1:]
                ypos = coordinates[1][:-1]
                mouse.position = (coordinates[0][1:], coordinates[1][:-1])

                # Get the right scroll arguments and perform scroll
                scrollArgs = arguments[1].split(",", 1)
                stArg = scrollArgs[0][1:]
                ndArg = scrollArgs[1][:-1]
                mouse.scroll(int(stArg), int(ndArg))
            else:
                # Move mouse to the right position
                coordinates = details[eventCount].split(",", 1)
                xpos = coordinates[0][1:]
                ypos = coordinates[1][:-1]
                mouse.position = (xpos, ypos)
                # Press and release
                mouse.press(stringToButton(str(action)))
                mouse.release(stringToButton(str(action)))
        else:
            # Remove quotation marks
            event = action[eventCount].replace("'", "")
            if details[eventCount] == 'Press':
                if len(event) == 1:
                    keyboard.press(event)
                else:
                    keyboard.press(stringToKey(event))
            else:
                if len(event) == 1:
                    keyboard.release(event)
                else:
                    keyboard.release(stringToKey(event))

        eventCount += 1
Пример #15
0
class MouseController():
    def __init__(self):
        pass
        self.mouse = Controller()

    def mouse_position(self):
        # Read pointer position
        print('The current pointer position is {0}'.format(
            self.mouse.position))
        return self.mouse.position

    def mouse_postiion_set(self, x, y):

        # Set pointer position
        self.mouse.position = (x, y)
        print('Now we have moved it to {0}'.format(self.mouse.position))

    def mouse_move(self, x, y):
        # Move pointer relative to current position
        self.mouse.move(x, y)

    def mouse_press(self, right=False):
        if right == True:
            self.mouse.press(Button.right)
        else:
            self.mouse.press(Button.left)

    def mouse_release(self, right=False):
        if right == True:
            self.mouse.release(Button.right)
        else:
            self.mouse.release(Button.left)

    def mouse_double_click(self, right=False):
        # Double click; this is different from pressing and releasing
        # twice on Mac OSX
        if right == 'right' or right == True:
            self.mouse.click(Button.right, 2)
        else:
            self.mouse.click(Button.right, 2)

    def mouse_scroll(self, x, y):
        # Scroll two steps down
        self.mouse.scroll(x, y)
Пример #16
0
class Main():
    def __init__(self):
        self.mouse = Controller()
        while True:
            with open("/dev/input/js0", "rb") as self.controller:
                self.controller.read(168)
                self.input = self.controller.read(8).hex()
                if self.input[-4:-2] == "01":
                    if self.input[-8:-6] == "01":
                        if self.input[-4:] == "0101":
                            self.mouse.press(Button.left)
                        if self.input[-4:] == "0100":
                            self.mouse.press(Button.right)
                    if self.input[-8:-6] == "00":
                        if self.input[-4:] == "0101":
                            self.mouse.release(Button.left)
                        if self.input[-4:] == "0100":
                            self.mouse.release(Button.right)
                if self.input[-4:-2] == "02":
                    if self.input[-2:] == "00":
                        if int(self.input[-6:-4], 16) > 127:
                            self.movement = int(self.input[-6:-4], 16) - 255
                        else:
                            self.movement = int(self.input[-6:-4], 16)
                        self.mouse.move(self.movement / 2, 0)
                    if self.input[-2:] == "01":
                        if int(self.input[-6:-4], 16) > 127:
                            self.movement = int(self.input[-6:-4], 16) - 255
                        else:
                            self.movement = int(self.input[-6:-4], 16)
                        self.mouse.move(0, self.movement / 2)
                    if self.input[-2:] == "02":
                        if int(self.input[-6:-4], 16) > 127:
                            self.movement = int(self.input[-6:-4], 16) - 255
                        else:
                            self.movement = int(self.input[-6:-4], 16)
                        self.mouse.scroll(-self.movement / 2, 0)
                    if self.input[-2:] == "03":
                        if int(self.input[-6:-4], 16) > 127:
                            self.movement = int(self.input[-6:-4], 16) - 255
                        else:
                            self.movement = int(self.input[-6:-4], 16)
                        self.mouse.scroll(0, -self.movement / 2)
Пример #17
0
    def mouseScroll(cls, dy, dx=0, mouseObject=None):
        if mouseObject == None:
            mouse = Controller()
        else:
            mouse = mouseObject
        mouse.scroll(dx, dy)


#test for mouseController
# mouse=mouseController.createMouseObject()

# position=mouseController.getMousePosition(mouse)
# print(position)

# mouseController.mouseTeleportDistance(-200,-500,mouse)
# time.sleep(3)
# position=mouseController.getMousePosition(mouse)
# print(position)

# mouseController.mouseTeleportToSP(1280,520)
# time.sleep(3)
# mouseController.mouseLeftPress(mouse)
# mouseController.mouseMoveByStep(1560,1040)
# time.sleep(5)
# print(mouse.position)
# mouseController.mouseLeftRelease(mouse)

# mouseController.mouseTeleportToSP(1280,520)
# mouseController.mouseRightPress(mouse)
# mouseController.mouseMoveByStep(1560,1040)
# time.sleep(5)
# print(mouse.position)
# mouseController.mouseRightRelease(mouse)
# time.sleep(6)

# mouseController.mouseTeleportToSP(1092,1325)
# mouseController.mouseLeftClick(mouse)
# time.sleep(3)
# mouseController.mouseRightClick(mouse)

# for i in range(100):
#     mouseController.mouseScroll(-10)
Пример #18
0
    def auto_roll(self, area):
        """自动滚动截屏,总函数"""
        x, y, w, h = area
        self.img_width = w
        self.img_height = h
        speed = round(1 / self.roll_speed, 2)
        screen = QApplication.primaryScreen()
        controler = MouseController()
        find_pos = Commen_Thread(self.efind_the_pos)
        self.in_rolling = True
        i = 0
        controler.position = (area[0] + int(area[2] / 2),
                              area[1] + int(area[3] / 2))
        while self.in_rolling:
            pix = screen.grabWindow(QApplication.desktop().winId(), x, y, w,
                                    h)  # 区域截屏获取图像pixmap
            img = self.qpix_to_cv2(pix)  # 将qt的pixmap转为pil模块的img对象
            self.img_list.append(img)  # 储存图片的列表
            if i >= 1:
                if self.is_same(self.img_list[i - 1],
                                self.img_list[i]):  # 每帧检查是否停止(图片是否相同)
                    self.in_rolling = False
                    i += 1
                    break
                if i == 5:  # 图片大于5张才开始寻找拼接点
                    find_pos.start()
            controler.scroll(dx=0, dy=-3)  # 滚动屏幕
            time.sleep(0.1)  # 速度控制
            cv2.imwrite('j_temp/{0}.png'.format(i), img)
            i += 1
        print('图片数', i)
        self.max_arrange = i - 1  # 获取图片序列用于控制寻找边界点的结束
        if i <= 2:
            print('过短!一张图还不如直接截呐')
            self.clear_timer.start(0)
            return
        else:
            find_pos.wait()  # 等待拼接点寻找完成
        print('found_pos_done')
        self.merge_all()  # 调用图片拼接函数

        self.clear_timer.start(10000)  # 10s后初始化内存
Пример #19
0
def read_setence(controller: Controller, setence: Setence):
    '''Read the keyboard setence and press or release its key.'''
    sleep(setence.pause)

    if setence.action == 'mv':
        current_position = controller.position
        position = [int(pos) for pos in setence.metadata.split(',')]

        controller.position = tuple(position)

    elif setence.action == 'sc':
        scroll = (int(delta) for delta in setence.metadata.split(','))
        controller.scroll(scroll[0], scroll[1])

    else:
        button = Button[setence.metadata]
        if setence.action == 'ps':
            controller.press(button)
        else:
            controller.release(button)
Пример #20
0
    def selectPlugin(self, plugin_item):
        plugin = self.getPlugin(plugin_item)

        try:
            findObject(plugin)
            waitForObject(plugin, 500)
            self.click(plugin)
        except LookupError:
            """
            Make sure that our mouse is within has focus on the marketplace window, 
            but ONLY the first time (i.e., once it's opened
            """
            try:
                waitForObject(names.mar_featured, 500).visible
                self.click(names.mar_featured)
            except LookupError:
                pass

            # Do the actual scroll
            mousecheck = Controller()
            mousecheck.scroll(0, -3)
            self.selectPlugin(plugin_item)
Пример #21
0
class Mouse:
    def __init__(self, sleep=0):
        self.mouse = Controller()
        self.sleep = sleep

    def get_position(self):
        # Get current pointer position
        sleep(self.sleep)
        print("The current pointer position is {0}".format(
            self.mouse.position))

    def set_position(self, x, y):
        # Set pointer position
        sleep(self.sleep)
        self.mouse.position = (x, y)
        print("Now we have moved it to {0}".format(self.mouse.position))

    def move(self, x, y):
        # Move pointer relative to current position
        sleep(self.sleep)
        self.mouse.move(x, y)

    def click(self):
        # Press and release
        sleep(self.sleep)
        self.mouse.press(Button.left)
        self.mouse.release(Button.left)

    def double_click(self):
        sleep(self.sleep)
        # Double click; this is different from pressing and releasing
        # twice on macOS
        self.mouse.click(Button.left, 2)

    def scroll(self, x, y):
        # Scroll two steps down
        sleep(self.sleep)
        self.mouse.scroll(x, y)
Пример #22
0
class MouseKeyboardThread(threading.Thread):
    def __init__(self, conn, addr):
        self.mouse = MouseController()
        self.keyboard = KeyoardController()
        threading.Thread.__init__(self)
        self.conn = conn
        self.addr = addr
        print("Accepting connection from: {0}:{1} ".format(*self.addr))

    def run(self):
        while True:
            data = self.conn.recv(1024)
            if not data:
                print("{0}:{1}: Connection closed".format(*self.addr))
                break
            self.__process_data(data)
        self.conn.close()

    def __process_data(self, data):
        try:
            e = MouseKeyboardEvent.decode(data)
        except:
            return
        print(e)
        if e.type == MouseKeyboardEvent.Type.MOUSE_ON_MOVE:
            self.mouse.position = (e.x * WIDTH, e.y * HEIGHT)
        elif e.type == MouseKeyboardEvent.Type.MOUSE_ON_CLICK:
            if e.pressed:
                self.mouse.press(e.button)
            else:
                self.mouse.release(e.button)
        elif e.type == MouseKeyboardEvent.Type.MOUSE_ON_SCROLL:
            self.mouse.scroll(e.dx, e.dy)
        elif e.type == MouseKeyboardEvent.Type.KEYBOARD_ON_PRESSED:
            self.keyboard.press(e.key)
        elif e.type == MouseKeyboardEvent.Type.KEYBOARD_ON_RELEASED:
            self.keyboard.release(e.key)
Пример #23
0
def process():
    name = request.form['site']
    if 'gledalica.com' in name:
        webbrowser.open_new(name)
        time.sleep(4.5)
        mouse = Controller()
        mouse.position = (700, 700)
        mouse.scroll(0, -470)
        time.sleep(0.5)
        mouse.click(Button.left, 3)
        time.sleep(1)
        pyautogui.hotkey('alt', 'f4')
        pyautogui.hotkey('alt', 'f4')
    elif 'filmovi.infopult.net' in name:
        webbrowser.open_new(name)
        time.sleep(4.5)
        mouse = Controller()
        mouse.position = (700, 700)
        mouse.click(Button.left, 1)
        time.sleep(1)
        pyautogui.hotkey('alt', 'f4')
    elif 'vipserije.com' in name:
        webbrowser.open_new(name)
        time.sleep(4.5)
        mouse = Controller()
        mouse.position = (700, 500)
        mouse.click(Button.left, 3)
        time.sleep(1)
        pyautogui.hotkey('ctrl', 'w')
        pyautogui.hotkey('ctrl', 'w')
    else:
        return render_template('error.html')

    if name == '':
        return render_template('error.html')
    else:
        return render_template('index.html')
Пример #24
0
    x = requests.get("http://192.168.6.42:5000/")
    queue = x.json()['queue']
    if len(queue) == 0:
        continue
    print(queue)
    for action in queue:
        if action == 'Swiping Left':
            print('move mouse left')
            mouse.move(-50, 0)
        if action == 'Swiping Right':
            print('move mouse right')
            mouse.move(50, 0)
        if action == 'Swiping Down':
            print('move mouse down')
            mouse.move(0, 50)
        if action == 'Swiping Up':
            print('move mouse up')
            mouse.move(0, -50)
        if action == 'Sliding Two Fingers Up':
            print('scroll mouse up')
            mouse.scroll(0, 5)
        if action == 'Sliding Two Fingers Down':
            print('scroll mouse down')
            mouse.scroll(0, -5)
        if action == 'Thumb Up':
            print('click right')
            mouse.click(Button.right, 1)
        if action == 'Thumb Down':
            print('click left')
            mouse.click(Button.left, 1)
Пример #25
0
class VirtualMouse:

    def __init__(self, eeg: EEG, model: MLModel, mouse_actions: List[str]):

        self.mouse = Controller_mouse()
        self.keyboard = Controller_keyboard()
        self.actions = {'right click': self.right_click, 'left click': self.left_click,
                        'double click': self.double_click, 'ctrl + c': self.ctrl_c, 'ctrl + v': self.ctrl_v,
                        'left press': self.left_press, 'left release': self.left_release,
                        'scroll up': self.scroll_up, 'scroll down': self.scroll_down}
        self.eeg: EEG = eeg
        self.model: MLModel = model

        # Assert all actions from the config object exist in the virtual mouse object
        self.assert_actions(mouse_actions)

    def assert_actions(self, config_actions: List[str]):
        """
        The method assert all the action in ConfigMouse exist in VirtualMouse
        :param config_actions: list with all the actions which represent to user
        :return:
        """
        for a in config_actions:

            if (a is not 'None') and (a.lower() not in self.actions.keys()):

                raise ValueError(f'The action `{a}` is in ConfigMouse but not implemented in VirtualMouse')

    def monitor(self, r: float, counter_limit: int, interval: float) -> bool:

        x_center, y_center = self.mouse.position
        counter = 0

        while counter < counter_limit:

            x, y = self.mouse.position

            if ((x - x_center) ** 2) + ((y - y_center) ** 2) < r ** 2:

                counter += 1
                # print(f'Counter: {counter}')

            else:

                x_center, y_center = x, y
                counter = 0

            time.sleep(interval)

        print('No movement monitored...')
        return True

    def predict(self, buffer_time: int) -> int:
        """
        Predict the label the user imagined.
        :param buffer_time: time of data acquisition in seconds
        :return:
        """
        # todo: what about the threshold? predict according the first label?

        # Sleep in order to get EEG data
        print('Predicting label...')
        time.sleep(buffer_time)

        # Data Acquisition
        data = self.eeg.get_channels_data()

        # Predict label
        prediction = self.model.online_predict(data, eeg=self.eeg)

        return prediction

    def execute(self, action: str):
        """
        The method execute the given action
        :param action: the action to execute as str
        :return:
        """

        # Debug
        print(f'Executing action: {action}')

        if action is not None:

            self.actions[action.lower()]()

    def right_click(self):
        self.mouse.press(Button.right)
        self.mouse.release(Button.right)

    def left_click(self):
        self.mouse.press(Button.left)
        self.mouse.release(Button.left)

    def double_click(self):
        self.mouse.click(Button.left, 2)

    def left_press(self):
        self.mouse.press(Button.right)

    def left_release(self):
        self.mouse.release(Button.left)

    def scroll_up(self):
        self.mouse.scroll(0, 2)

    def scroll_down(self):
        self.mouse.scroll(0, -2)

    def ctrl_c(self):

        # Choose the file under the cursor
        self.mouse.press(Button.left)
        self.mouse.release(Button.left)

        # ctrl+c it!
        with self.keyboard.pressed(Key.ctrl):
            self.keyboard.press('c')
            self.keyboard.release('c')

    def ctrl_v(self):

        # Choose the file under the cursor
        self.mouse.press(Button.left)
        self.mouse.release(Button.left)

        # ctrl+v it!
        with self.keyboard.pressed(Key.ctrl):
            self.keyboard.press('v')
            self.keyboard.release('v')
Пример #26
0
                    elif dist_thumb_mid > 0 and dist_thumb_mid < 15:
                        if db_click_flag == 0:
                            db_click_flag = 1

                            cv2.putText(frame, "Double Click", (30, 22),
                                        cv2.FONT_HERSHEY_COMPLEX_SMALL, 1,
                                        (0, 255, 255), 2)
                            mouse.click(Button.left, 2)
                    elif dist_thumb_pinky > 0 and dist_thumb_pinky < 15:
                        if scroll_down_flag == 0:
                            db_click_flag = 0
                            scroll_down_flag = 1
                            cv2.putText(frame, "Scroll Down", (320, 22),
                                        cv2.FONT_HERSHEY_COMPLEX_SMALL, 1,
                                        (0, 0, 255), 2)
                            mouse.scroll(0, -2)
                    elif dist_thumb_ring > 0 and dist_thumb_ring < 15:
                        if scroll_up_flag == 0:
                            db_click_flag = 0
                            scroll_up_flag = 1
                            mouse.scroll(0, 2)

                except:
                    pass

    cv2.imshow("frame", frame)
    if cv2.waitKey(1) == ord('q'):
        break

cv2.destroyAllWindows()
Пример #27
0
keyboard.type(senha)
sleep(1.0)

# Finaliza Cadastro
mouse.position = (795, 670)
sleep(1.0)
mouse.click(Button.left)
sleep(3.0)

mouse.position = (795, 570)
sleep(1.0)
mouse.click(Button.left)

# Mostra menu
sleep(5.0)
mouse.scroll(0, -3)
sleep(2.5)
mouse.scroll(0, 3)
sleep(2.0)
mouse.position = (740, 365)
sleep(1.0)
mouse.click(Button.left)
sleep(4.0)

# Cadastra infos
mouse.click(Button.left)
sleep(1.0)
keyboard.type(cpf)
sleep(0.5)

mouse.move(0, 135)
Пример #28
0
from pynput.mouse import Button, Controller
import time 
 
mouse = Controller()
print(mouse.position)
time.sleep(3)
print('The current pointer position is {0}'.format(mouse.position))
 
 
#set pointer positon
mouse.position = (277, 645)
print('now we have moved it to {0}'.format(mouse.position))
 
#鼠标移动(x,y)个距离
mouse.move(5, -5)
print(mouse.position)
 
mouse.press(Button.left)
mouse.release(Button.left)
 
#Double click
mouse.click(Button.left, 1)
 
#scroll two steps down
mouse.scroll(0, 500)
Пример #29
0
        audio = r.adjust_for_ambient_noise(source)

        audio = r.listen(source, phrase_time_limit=4)
        print('Say Anything')
        balloon_tip('Say Anything', 'Say it now!!!')

        try:
            text = r.recognize_google(audio)

            print("You said : {}".format(text))
            balloon_tip('Received', "You said : {}".format(text))

            str = format(text)

            if ('scroll down' in str):
                mouse.scroll(0, -50)
                str = ''
            if ('scroll up' in str):
                mouse.scroll(0, 50)
                str = ''

            if ('1, 1' in str):
                mouse.position = (160, 80)
                str = ''
            if ('1, 2' in str):
                mouse.position = (520, 80)
                str = ''
            if ('1, 3' in str):
                mouse.position = (880, 80)
                str = ''
            if ('1, 4' in str):
Пример #30
0
from pynput.mouse import Button, Controller
import keyboard
from time import sleep
import tkinter as tk

mouse = Controller()

start = input("Press any key to start the program")

while(True):
    mouse.scroll(0,1)
    if keyboard.is_pressed("esc"):
        print("Exiting Program")
        break
    sleep(0.05)