Ejemplo n.º 1
0
    def _play(self, speed_factor=7.0, include_clicks=True, include_moves=True, include_wheel=True):
        # For hotkey management
        state = keyboard.stash_state()

        last_time = None
        for event in self.events:
            if speed_factor > 0 and last_time is not None:
                time.sleep((event.time - last_time) / speed_factor)
            last_time = event.time

            if isinstance(event, KeyboardEvent):
                key = event.scan_code or event.name
                keyboard.press(key) if event.event_type == KEY_DOWN else keyboard.release(key)

            if isinstance(event, ButtonEvent) and include_clicks:
                if event.event_type == UP:
                    mouse.release(event.button)
                else:
                    mouse.press(event.button)
            elif isinstance(event, MoveEvent) and include_moves:
                mouse.move(event.x, event.y)
            elif isinstance(event, WheelEvent) and include_wheel:
                mouse.wheel(event.delta)

        # For hotkey management
        keyboard.restore_modifiers(state)
Ejemplo n.º 2
0
def wheel_at(h_wnd: int, delta: int) -> None:
    with recover_foreground():
        set_forground(h_wnd)
        for _ in range(abs(delta)):
            mouse.wheel(1 if delta > 0 else -1)
            time.sleep(1 / 120.0)
        time.sleep(1)
 def scrollToRow(self,
                 target_row,
                 max_scrolls=20,
                 extra_scroll=0,
                 interval=0.05):
     in_between_row = False
     rows_scrolled = 0
     lines_scrolled = 0
     while True:
         pix = captureWindow(self.game_info.hwnd,
                             (self.game_info.scroll_fin_keypt_x,
                              self.game_info.scroll_fin_keypt_y,
                              self.game_info.scroll_fin_keypt_x + 1.5,
                              self.game_info.scroll_fin_keypt_y + 1.5))
         if abs(pix.getpixel((0, 0))[0] -
                233) > 5 or abs(pix.getpixel((0, 0))[1] - 229) > 5 or abs(
                    pix.getpixel((0, 0))[2] - 220) > 5:
             # if in_between_row==False:
             #     print('到行之间了')
             in_between_row = True
         elif in_between_row:
             in_between_row = False
             rows_scrolled += 1
             lines_scrolled = 0
             # print(f'已翻{rows_scrolled}行')
             if rows_scrolled >= target_row:
                 for _ in range(extra_scroll):
                     mouse.wheel(-1)
                 return rows_scrolled
         if lines_scrolled > max_scrolls:
             return rows_scrolled
         get_first_art = lambda: np.array(
             captureWindow(
                 self.game_info.hwnd,
                 (self.game_info.first_art_x + self.game_info.art_width / 2
                  - 1, self.game_info.first_art_y + self.game_info.
                  art_height / 2, self.game_info.first_art_x + self.
                  game_info.art_width / 2 + 1, self.game_info.first_art_y +
                  self.game_info.art_height)))
         first_art = get_first_art()
         for _ in range(7 if lines_scrolled == 0 and target_row > 0 else 1):
             mouse.wheel(-1)
             lines_scrolled += 1
             # print('翻一下')
         time.sleep(self.avg_response_time)
         total_waited = 0
         while True:
             if total_waited > 5:
                 break
             if np.max(np.abs(get_first_art() - first_art)) > 5:
                 break
             time.sleep(interval)
             total_waited += interval
Ejemplo n.º 4
0
def zoom(transcript):
    in_or_out = transcript.split()
    if in_or_out[1] == "in":
        keyboard.press("ctrl")
        sleep()
        mouse.wheel(delta=5)
        sleep()
        keyboard.release("ctrl")

    elif in_or_out[1] == "out":
        keyboard.press("ctrl")
        sleep()
        mouse.wheel(delta=-5)
        sleep()
        keyboard.release("ctrl")
Ejemplo n.º 5
0
def focus(cur_foc):
    if int(cur_foc) != 0:
        if (cur_foc > 0):
            keyboard.press('ctrl')
            time.sleep(.01)
            mouse.wheel(1)
            cur_foc -= 1
        elif (cur_foc < 0):
            keyboard.press('ctrl')
            time.sleep(.01)
            mouse.wheel(-1)
            cur_foc += 1
        time.sleep(.01)
        keyboard.release('ctrl')

    return cur_foc
Ejemplo n.º 6
0
def start_game_macro():
    time.sleep(.1)
    keyboard.press('v')
    time.sleep(.1)
    mouse.move(*CHEESE_HUB_XY, duration=.16)
    time.sleep(.2)
    mouse.wheel(-9)
    click_mouse()
    time.sleep(.1)
    keyboard.press('tab')

    mouse.move(*PLAY_BUTTON_XY, duration=.16)
    time.sleep(.2)
    click_mouse()
    time.sleep(.1)
    click_mouse()
Ejemplo n.º 7
0
    def Op(key, op, ox, oy):
        # print(key, op, ox, oy)
        if key == 1:
            if op == 100:

                # 左键按下
                mouse.move(ox, oy)
                mouse.press(button=mouse.LEFT)
            elif op == 117:

                # 左键弹起
                x, y = mouse.get_position()
                if ox != x or oy != y:
                    if not mouse.is_pressed():
                        mouse.press(button=mouse.LEFT)
                    mouse.move(ox, oy)
                mouse.release(button=mouse.LEFT)
        elif key == 2:

            # 滚轮事件
            if op == 0:
                # 向上
                mouse.move(ox, oy)
                mouse.wheel(delta=-1)
            else:
                # 向下
                mouse.move(ox, oy)
                mouse.wheel(delta=1)

        elif key == 3:
            # 鼠标右键
            if op == 100:
                # 右键按下
                mouse.move(ox, oy)
                mouse.press(button=mouse.RIGHT)
            elif op == 117:
                # 右键弹起
                mouse.move(ox, oy)
                mouse.release(button=mouse.RIGHT)

        else:
            k = official_virtual_keys.get(key)
            if k is not None:
                if op == 100:  # 按键按下
                    keyboard.press(k)
                elif op == 117:  # 按键抬起
                    keyboard.release(k)
 def alignFirstRow(self):
     mouse.move(self.game_info.left + self.game_info.first_art_x,
                self.game_info.top + self.game_info.first_art_y)
     mouse.click()
     pix = captureWindow(self.game_info.hwnd,
                         (self.game_info.scroll_fin_keypt_x,
                          self.game_info.scroll_fin_keypt_y,
                          self.game_info.scroll_fin_keypt_x + 1.5,
                          self.game_info.scroll_fin_keypt_y + 1.5))
     if abs(pix.getpixel((0, 0))[0] -
            233) > 5 or abs(pix.getpixel((0, 0))[1] -
                            229) > 5 or abs(pix.getpixel((0, 0))[2] -
                                            220) > 5:
         for _ in range(3):
             mouse.wheel(1)
         time.sleep(0.1)
         self.scrollToRow(0)
Ejemplo n.º 9
0
def main():
    while True:
        logger.debug('Waiting for input...')
        val = int(ser.read()[0])
        logger.debug(f'Got {val}')

        if val == 31:
            logger.info('Left press')
            mouse.press(mouse.LEFT)
        elif val == 32:
            logger.info('Left release')
            mouse.release(mouse.LEFT)
        elif val == 41:
            logger.info('Middle press')
            mouse.press(mouse.MIDDLE)
        elif val == 42:
            logger.info('Middle release')
            mouse.release(mouse.MIDDLE)
        elif val == 51:
            logger.info('Right press')
            mouse.press(mouse.RIGHT)
        elif val == 52:
            logger.info('Right release')
            mouse.release(mouse.RIGHT)

        elif val == 1:
            logger.info('Move left')
            mouse.move(x=-1, y=0, absolute=False)
        elif val == 2:
            logger.info('Move right')
            mouse.move(x=1, y=0, absolute=False)
        elif val == 21:
            logger.info('Move up')
            mouse.move(y=-1, x=0, absolute=False)
        elif val == 22:
            logger.info('Move down')
            mouse.move(y=1, x=0, absolute=False)

        elif val == 11:
            logger.info('Wheel down')
            mouse.wheel(-1)
        elif val == 12:
            logger.info('Wheel up')
            mouse.wheel(1)
Ejemplo n.º 10
0
    def handle_held_button_repetition(self):
        while True:
            tick_time = now()

            on_hold = lambda: None if self.is_mouse_mode else keyboard.press(
                'left')
            on_release = lambda: self.release_mouse_if_pressed(
                'left') if self.is_mouse_mode else self.release_key_if_pressed(
                    'left')
            self.held_button_action(tick_time, "LEFT", on_hold, on_release)

            on_hold = lambda: mouse.press(
                button='right') if self.is_mouse_mode else keyboard.press(
                    'right')
            on_release = lambda: self.release_mouse_if_pressed(
                'right'
            ) if self.is_mouse_mode else self.release_key_if_pressed('right')
            self.held_button_action(tick_time, "RIGHT", on_hold, on_release)

            on_hold = lambda: mouse.wheel(
                delta=1) if self.is_mouse_mode else keyboard.press('up')
            on_release = lambda: None if self.is_mouse_mode else self.release_key_if_pressed(
                'up')
            self.held_button_action(tick_time, "UP", on_hold, on_release)

            on_hold = lambda: mouse.wheel(
                delta=-1) if self.is_mouse_mode else keyboard.press('down')
            on_release = lambda: None if self.is_mouse_mode else self.release_key_if_pressed(
                'down')
            self.held_button_action(tick_time, "DOWN", on_hold, on_release)

            def get_current_action(btn, action_idx):
                action_name = self.current_padboard_grill[self.is_pressed[btn]
                                                          [2]][action_idx]
                return get_actions_by_name(action_name)

            for btn, action_idx in [('BTN_NORTH', 0), ('BTN_WEST', 1),
                                    ('BTN_EAST', 2), ('BTN_SOUTH', 3)]:
                on_hold = lambda: get_current_action(btn, action_idx)[1]()
                on_release = lambda: get_current_action(btn, action_idx)[2]()
                self.held_button_action(tick_time, btn, on_hold, on_release)

            time.sleep(self.rapid_fired_frequency)
Ejemplo n.º 11
0
    def _thread_play(self,
                     cv,
                     events,
                     speed_factor=1.0,
                     include_clicks=True,
                     include_moves=True,
                     include_wheel=True):
        """
        Thread that plays both the mouse and keyboard events back.
        This thread will stop the playback if stop_replay == True
        """
        last_time = None
        state = keyboard.stash_state()
        for event_type, event in events:
            # Awaken interrupt thread to check for exit status
            cv.set()
            if self.stop_replay:
                return
            if speed_factor > 0 and last_time is not None:
                time.sleep((event.time - last_time) / speed_factor)
            last_time = event.time

            if event_type == 'mouse':
                if isinstance(event, ButtonEvent) and include_clicks:
                    if event.event_type == UP:
                        gui.mouseUp(button=event.button)
                    else:
                        gui.mouseDown(button=event.button)
                elif isinstance(event, MoveEvent) and include_moves:
                    mouse.move(event.x, event.y)
                elif isinstance(event, WheelEvent) and include_wheel:
                    mouse.wheel(event.delta)
            elif event_type == 'keyboard':
                key = event.name or event.scan_code
                keyboard.press(
                    key) if event.event_type == KEY_DOWN else keyboard.release(
                        key)
            else:
                raise Exception("Incorrect type of event")
        keyboard.restore_modifiers(state)
Ejemplo n.º 12
0
    def wheel(self, direction, steps):
        """ Clicks the wheel the specified number of steps in the given direction.

        Use Mouse.WHEEL_DOWN, Mouse.WHEEL_UP
        """
        self._lock.acquire()
        if direction == 1:
            wheel_moved = steps
        elif direction == 0:
            wheel_moved = -1 * steps
        else:
            raise ValueError("Expected direction to be 1 or 0")
        self._lock.release()
        return mouse.wheel(wheel_moved)
Ejemplo n.º 13
0
 def scrollUp():
     for i in range(1,LIMIT):
         mouse.wheel(0.01)
         time.sleep(PAUSE)
         print("Up")
Ejemplo n.º 14
0
server_addr = ('0.0.0.0', 6666)
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_socket.bind(server_addr)
print(
    f'Ready to receive commands on port: {server_addr[1]} with public IP addr: {ip_addr}'
)

while True:
    msg, client_addr = udp_socket.recvfrom(1024)
    msg = msg.decode()
    print(
        f'Received msg: {msg} at {datetime.now().strftime("%Y/%m/%d %I:%M:%S%p")} from {client_addr}'
    )

    try:
        cmd, param = msg.split(':')
        if cmd == 'move':
            x, y = param.split(',')
            mouse.move(x, y, absolute=True, duration=0)
        elif cmd == 'wheel':
            mouse.wheel(int(param))
        elif cmd == 'button up':
            mouse.press(param)
        elif cmd == 'button down':
            mouse.release(param)
        else:
            print('Received an unknown command')
    except ValueError:
        print('ValueError caused by wrong msg format')
# end while
Ejemplo n.º 15
0
    def filter_key(self, event):
        if event.name == 'z' and event.event_type == 'up':
            print(event.name, event.event_type)

            print('left mouse is down')
            mouse.press(mouse.LEFT)

            time.sleep(self.HOULD_TIME)

            print('left mouse is up')
            mouse.release(mouse.LEFT)

        elif event.name == 'x' and event.event_type == 'up':
            print(event.name, event.event_type, event.time)

            print('right mouse is down')
            mouse.press(mouse.RIGHT)

            # sleep for some time
            time.sleep(self.HOULD_TIME)

            print('right mouse is up')
            mouse.release(mouse.RIGHT)

        elif event.name == 'v' and event.event_type == 'up':
            print(event.name, event.event_type, event.time)

            print('right mouse is click')
            mouse.click(mouse.RIGHT)

        elif event.name == 'c' and event.event_type == 'up':
            print(event.name, event.event_type)

            print('middle mouse is down')
            mouse.press(mouse.MIDDLE)

            # sleep for some time
            # time.sleep(self.HOULD_TIME)

            print('midle mouse is up')
            mouse.release(mouse.MIDDLE)

        elif event.name == 'u' and event.event_type == 'up':
            print(event.name, event.event_type)

            print('scroll mouse wheel up')
            mouse.wheel(1)

        elif event.name == 'j' and event.event_type == 'up':
            print(event.name, event.event_type)

            print('scroll mouse wheel down')
            mouse.wheel(-1)

        elif event.name == 'esc' and event.event_type == 'up':
            print(event.name, event.event_type)
            # exit
            keyboard.wait()
            self.run = False

            print('esc key is down exiting')
Ejemplo n.º 16
0
    def input_loop(self):
        ANALOG_STICK_MAX_RAW_VALUE = math.pow(2, 15)
        ANALOG_STICK_DEADZONE_THRESHOLD = 0.33
        ANALOG_STICK_DEADZONE_FOR_MOUSE = 0.12
        TRIGGER_DEADZONE_THRESHOLD = 10
        MOVING_VELOCITY_CONSTANT = 15 * 3
        MOVING_MOUSE_VELOCITY_CONSTANT = 8

        y_axis = 'CENTER'
        x_axis = 'CENTER'

        is_L2_pressed = False
        is_R2_pressed = False
        is_START_pressed = False
        is_SELECT_pressed = False

        def reset_mouse_mode_sensitive_buttons():
            self.is_pressed['UP'] = (False, None)
            self.is_pressed['DOWN'] = (False, None)
            self.is_pressed['LEFT'] = (False, None)
            self.is_pressed['RIGHT'] = (False, None)
            self.release_key_if_pressed('up')
            self.release_key_if_pressed('down')
            self.release_key_if_pressed('left')
            self.release_key_if_pressed('right')
            self.release_mouse_if_pressed('left')
            self.release_mouse_if_pressed('right')

        inputs_library_patches.waitng_for_controller()
        self.init_input_held_buttons_handling()

        while True:
            try:
                events = get_gamepad()
                for event in events:

                    # Change Tile grid
                    if event.code == 'BTN_TL':
                        if event.state == 0:
                            self.current_padboard_grill = tiles[
                                self.current_padboard_tile].foreground_grill
                            self.is_L1_pressed = False
                        else:
                            self.current_padboard_grill = tiles[
                                self.current_padboard_tile].background_grill
                            self.is_L1_pressed = True

                    # Handle Window Hide/show
                    elif event.code == 'BTN_START':
                        if event.state == 0:
                            is_START_pressed = False
                        else:
                            is_START_pressed = True
                            if self.is_L1_pressed and is_SELECT_pressed:
                                self.is_in_pause = not self.is_in_pause

                    elif event.code == 'BTN_SELECT':
                        if event.state == 0:
                            is_SELECT_pressed = False
                        else:
                            is_SELECT_pressed = True
                            if self.is_L1_pressed and is_START_pressed:
                                self.is_in_pause = not self.is_in_pause
                    elif self.is_in_pause:
                        continue

                    # Handle ALT, CTRL, SHIFT
                    elif event.code == 'ABS_Z':
                        if not ((event.state > TRIGGER_DEADZONE_THRESHOLD)
                                == is_L2_pressed):
                            is_L2_pressed = not is_L2_pressed
                            if is_L2_pressed:
                                keyboard.press("alt")
                            else:
                                keyboard.release("alt")

                    elif event.code == 'ABS_RZ':
                        if not ((event.state > TRIGGER_DEADZONE_THRESHOLD)
                                == is_R2_pressed):
                            is_R2_pressed = not is_R2_pressed
                            if is_R2_pressed:
                                keyboard.press("ctrl")
                            else:
                                keyboard.release("ctrl")

                    elif event.code == 'BTN_TR':
                        if event.state == 0:
                            keyboard.release("shift")
                        else:
                            keyboard.press("shift")

                    # Handle Actions
                    elif self.handle_action_input(event, 'BTN_NORTH', 0):
                        pass
                    elif self.handle_action_input(event, 'BTN_WEST', 1):
                        pass
                    elif self.handle_action_input(event, 'BTN_EAST', 2):
                        pass
                    elif self.handle_action_input(event, 'BTN_SOUTH', 3):
                        pass

                    # Handle Active Boxes
                    elif event.code == 'ABS_Y' or event.code == 'ABS_X':
                        if event.code == 'ABS_Y':
                            y_val = event.state / ANALOG_STICK_MAX_RAW_VALUE
                            if y_val > ANALOG_STICK_DEADZONE_THRESHOLD:
                                y_axis = 'TOP'
                            elif y_val < -ANALOG_STICK_DEADZONE_THRESHOLD:
                                y_axis = 'BOTTOM'
                            else:
                                y_axis = 'CENTER'

                        elif event.code == 'ABS_X':
                            x_val = event.state / ANALOG_STICK_MAX_RAW_VALUE
                            if x_val > ANALOG_STICK_DEADZONE_THRESHOLD:
                                x_axis = 'RIGHT'
                            elif x_val < -ANALOG_STICK_DEADZONE_THRESHOLD:
                                x_axis = 'LEFT'
                            else:
                                x_axis = 'CENTER'

                        if y_axis == 'TOP':
                            if x_axis == 'LEFT':
                                self.active_box = 0
                            elif x_axis == 'RIGHT':
                                self.active_box = 2
                            else:
                                self.active_box = 1
                        elif y_axis == 'BOTTOM':
                            if x_axis == 'LEFT':
                                self.active_box = 6
                            elif x_axis == 'RIGHT':
                                self.active_box = 8
                            else:
                                self.active_box = 7
                        else:
                            if x_axis == 'LEFT':
                                self.active_box = 3
                            elif x_axis == 'RIGHT':
                                self.active_box = 5
                            else:
                                self.active_box = 4

                    # Handle window moving
                    elif event.code == 'ABS_RY' and not self.is_mouse_mode:
                        value = event.state / ANALOG_STICK_MAX_RAW_VALUE
                        if value > ANALOG_STICK_DEADZONE_THRESHOLD or value < -ANALOG_STICK_DEADZONE_THRESHOLD:
                            self.WindowYPosVelocity = -int(
                                MOVING_VELOCITY_CONSTANT * value)
                        else:
                            self.WindowYPosVelocity = 0
                    elif event.code == 'ABS_RX' and not self.is_mouse_mode:
                        value = event.state / ANALOG_STICK_MAX_RAW_VALUE
                        if value > ANALOG_STICK_DEADZONE_THRESHOLD or value < -ANALOG_STICK_DEADZONE_THRESHOLD:
                            self.WindowXPosVelocity = int(
                                MOVING_VELOCITY_CONSTANT * value)
                        else:
                            self.WindowXPosVelocity = 0

                    # Handle Tile Changing
                    elif event.code == 'BTN_THUMBL':
                        if event.state == 1:
                            self.current_padboard_tile = (
                                self.current_padboard_tile + 1) % len(tiles)
                            self.current_padboard_grill = tiles[
                                self.current_padboard_tile].foreground_grill

                    # Handle Arrows
                    elif event.code == 'ABS_HAT0Y' and not self.is_mouse_mode:
                        if event.state == 1:  # DOWN ARROW
                            keyboard.press("down")
                            self.is_pressed['DOWN'] = (True, now())
                        elif event.state == -1:  # UP ARROW
                            keyboard.press("up")
                            self.is_pressed['UP'] = (True, now())
                        else:
                            self.is_pressed['UP'] = (False, None)
                            self.is_pressed['DOWN'] = (False, None)
                            self.release_key_if_pressed('up')
                            self.release_key_if_pressed('down')

                    elif event.code == 'ABS_HAT0X' and not self.is_mouse_mode:
                        if event.state == -1:  # LEFT ARROW
                            keyboard.press("left")
                            self.is_pressed['LEFT'] = (True, now())
                        elif event.state == 1:  # RIGHT ARROW
                            keyboard.press("right")
                            self.is_pressed['RIGHT'] = (True, now())
                            pass
                        else:
                            self.is_pressed['LEFT'] = (False, None)
                            self.is_pressed['RIGHT'] = (False, None)
                            self.release_key_if_pressed('left')
                            self.release_key_if_pressed('right')

                    # Handle Mouse mode
                    elif event.code == 'BTN_THUMBR':
                        if event.state == 1:
                            reset_mouse_mode_sensitive_buttons()

                            self.is_mouse_mode = not self.is_mouse_mode
                            if self.is_mouse_mode:
                                print("MOUSE MODE ON")
                            else:
                                print("MOUSE MODE OFF")

                    # Mouse Buttons
                    elif event.code == 'ABS_HAT0Y' and self.is_mouse_mode:
                        if event.state == 1:  # DOWN ARROW
                            mouse.wheel(delta=-1)
                            self.is_pressed['DOWN'] = (True, now())
                        elif event.state == -1:  # UP ARROW
                            mouse.wheel(delta=1)
                            self.is_pressed['UP'] = (True, now())
                        else:
                            self.is_pressed['UP'] = (False, None)
                            self.is_pressed['DOWN'] = (False, None)
                    elif event.code == 'ABS_HAT0X' and self.is_mouse_mode:
                        if event.state == -1:  # LEFT ARROW
                            mouse.press(button='left')
                            self.is_pressed['LEFT'] = (True, now())
                        elif event.state == 1:  # RIGHT ARROW
                            mouse.press(button='right')
                            self.is_pressed['RIGHT'] = (True, now())
                            pass
                        else:
                            self.is_pressed['LEFT'] = (False, None)
                            self.is_pressed['RIGHT'] = (False, None)
                            self.release_mouse_if_pressed('left')
                            self.release_mouse_if_pressed('right')

                    # Mouse movement
                    elif event.code == 'ABS_RY' and self.is_mouse_mode:
                        moving_velocity = MOVING_MOUSE_VELOCITY_CONSTANT
                        value = event.state / ANALOG_STICK_MAX_RAW_VALUE
                        if value > ANALOG_STICK_DEADZONE_FOR_MOUSE or value < -ANALOG_STICK_DEADZONE_FOR_MOUSE:
                            self.MouseYPosVelocity = -int(
                                moving_velocity * value)
                        else:
                            self.MouseYPosVelocity = 0
                    elif event.code == 'ABS_RX' and self.is_mouse_mode:
                        moving_velocity = MOVING_MOUSE_VELOCITY_CONSTANT
                        value = event.state / ANALOG_STICK_MAX_RAW_VALUE
                        if value > ANALOG_STICK_DEADZONE_FOR_MOUSE or value < -ANALOG_STICK_DEADZONE_FOR_MOUSE:
                            self.MouseXPosVelocity = int(moving_velocity *
                                                         value)
                        else:
                            self.MouseXPosVelocity = 0
            except:
                print("Controller Disconnected")
                time.sleep(1)
Ejemplo n.º 17
0
import mouse, sys
import time
import serial

mouse.FAILSAFE = False
ArduinoSerial = serial.Serial('/dev/ttyACM0', 9600)  #
time.sleep(1)  #delay of 1 second

while 1:
    data = str(ArduinoSerial.readline().decode('ascii'))
    (x, y, z) = data.split(":")  # read the x and y axis data
    (x, y) = (int(x), int(y))  # convert to int
    mouse.move(x, y)  # move the cursor to desired coordinates
    if '1' in z:
        mouse.click(button="left")  #clicks mouse button
    elif '2' in z:
        mouse.click(button="right")
    elif '3' in z:
        mouse.wheel(delta=-1)  # Scroll down
    elif '4' in z:
        mouse.wheel(delta=1)  # Scroll up
Ejemplo n.º 18
0
 def wheelMouse(self, pos=None, direction=-1):
     if pos: self.moveMouse(pos)
     mouse.wheel(direction)
     pass
def linkedin():
    driver = webdriver.Chrome("E:/project/Uploader_Downloader/chromedriver")
    login = driver.get(
        "https://www.linkedin.com/uas/login?fromSignIn=true&trk=cold_join_sign_in"
    )
    time.sleep(1)
    user_id = driver.find_element_by_id("username").send_keys(
        "Enter your email id here")
    time.sleep(1)
    password = driver.find_element_by_id("password").send_keys(
        "Enter LinkedIn password here")
    time.sleep(3)
    driver.find_element_by_xpath(
        '//*[@id="app__container"]/main/div[2]/form/div[3]/button').click()
    if driver.title == "Security Verification | LinkedIn":
        otp = int(input("Enter OTP: "))
        driver.find_element_by_name("pin").send_keys(otp)
        time.sleep(3)
        driver.find_element_by_id("email-pin-submit-button").click()
    time.sleep(3)
    google = driver.get("https://www.google.com/")
    filters = 'site:Linkedin.com "Aditya Birla Sun Life Insurance" AND "India" AND "@yahoo.com"'
    driver.find_element_by_name('q').send_keys(filters)
    time.sleep(2)
    driver.find_element_by_xpath(
        '//*[@id="tsf"]/div[2]/div[1]/div[3]/center/input[1]').click()
    time.sleep(4)
    page_no = int(input("Enter page_number: "))
    for page in range(page_no):
        url = driver.current_url
        search_mail = driver.find_elements_by_class_name('st')
        google_page = driver.page_source
        source_page = BeautifulSoup(google_page, 'lxml')
        google_links = source_page.find_all('div', {'class': 'r'})
        for links_to_iterate in google_links:
            p_l = links_to_iterate.find('a', href=True)
            p_l = str(p_l)
            p_l = p_l.split()
            list_.append(p_l[1].strip('href=').strip('""'))
        for i in search_mail:
            mail = emails = re.findall(
                "([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)", i.text)
            print(mail)
        for x_path in list_:
            try:
                driver.get(x_path)
                time.sleep(2)
                mouse.wheel(-50)
                time.sleep(7)
            except:
                try:
                    sheet = pd.DataFrame([
                        full_name, first_name, last_name, working,
                        profile_page, position, years_of_experience,
                        years_of_experience_at_that_pos, institute,
                        qualification, time_of_qualification
                    ])
                    sheet.to_csv('FINAL Sheet.csv')
                    quit()
                except:
                    print("File is open please close the file")
                    input("Done? ")
                    sheet = pd.DataFrame([
                        full_name, first_name, last_name, working,
                        profile_page, position, years_of_experience,
                        years_of_experience_at_that_pos, institute,
                        qualification, time_of_qualification
                    ])
                    sheet.to_csv('FINAL Sheet.csv')
                    quit()
            try:
                src = driver.page_source
                html_page = BeautifulSoup(src, "lxml")
                profile_link = driver.current_url
                profile_link = str(profile_link)
                profile_page.append(profile_link)
            except:
                profile_page.append("No link provided")
            try:
                name_div = html_page.find('div', {'class': 'flex-1 mr5'})
                name_loc = name_div.find_all('ul')
                name = name_loc[0].find('li').get_text().strip()
                full_name.append(name)
                name = name.split()
                first = name[0]
                last = name[-1]

                first_name.append(first)
                last_name.append(last)
            except:
                full_name.append("No name found")
                first_name.append("No name found")
                last_name.append("No name found")
            try:
                profile_title = name_div.find(
                    'h2', {
                        'class': 'mt1 t-18 t-black t-normal break-words'
                    }).get_text().strip()
                position.append(profile_title)
            except:
                position.append('No profile title found')
            try:
                experience = html_page.find('h4',
                                            {'class': 't-14 t-black t-normal'})
                years_of_experience.append(
                    experience.get_text().strip('Total Duration\n'))
            except:
                years_of_experience.append("No experience provided")
            try:
                time_dur = driver.find_element_by_class_name(
                    'pv-entity__bullet-item-v2').text
                years_of_experience_at_that_pos.append(time_dur)
            except:
                years_of_experience_at_that_pos.append("Not provded")
            try:
                edu = driver.find_element_by_class_name(
                    'pv-entity__school-name').text
                institute.append(edu)
            except:
                institute.append("Not provided")
            try:
                spec = driver.find_elements_by_class_name(
                    'pv-entity__comma-item')
                qualification.append(spec[0].text + " " + spec[1].text)
            except:
                qualification.append("Not provided")
            try:
                time_of_edu = driver.find_elements_by_tag_name('time')
                time_of_qualification.append(time_of_edu[0].text + "-" +
                                             time_of_edu[1].text)
            except:
                time_of_qualification.append("Not provided")
            try:
                work = driver.find_element_by_class_name(
                    'pv-top-card--experience-list-item').text
                working.append(work)
            except:
                working.append("Not provided")
            if x_path == list_[len(list_) - 1]:
                try:
                    driver.get(url)
                    time.sleep(5)
                    driver.find_element_by_link_text('Next').click()
                    list_.clear()
                except:
                    if page == page_no - 1:
                        sheet = pd.DataFrame([
                            full_name, first_name, last_name, working,
                            profile_page, position, years_of_experience,
                            years_of_experience_at_that_pos, institute,
                            qualification, time_of_qualification
                        ])
                        sheet.to_csv('TEST_SHEETt.csv')
                        print("Excel sheet is ready...")
                        sys.exit()
                    else:
                        print("File is open please close the file")
                        input("Done? ")
                        sheet = pd.DataFrame([
                            full_name, first_name, last_name, working,
                            profile_page, position, years_of_experience,
                            years_of_experience_at_that_pos, institute,
                            qualification, time_of_qualification
                        ])
                        sheet.to_csv('TEST_SHEET.csv')
                        print("Excel sheet is ready...")
                        sys.exit()
Ejemplo n.º 20
0
            # SLOW
            elif keyboard.is_pressed('j'):
                mouse.move(0, mouse_movement_displacement, absolute=False)

            # UP
            # FAST
            if keyboard.is_pressed('shift+k'):
                mouse.move(0, -mouse_movement_displacement*mouse_movement_speed_up, absolute=False)
            # SLOW
            elif keyboard.is_pressed('k'):
                mouse.move(0, -mouse_movement_displacement, absolute=False)

            # CLICK LEFT
            if keyboard.is_pressed('p'):
                mouse.click()

            scroll_speed_up = 1
            scroll_displacement = 1
            # SCROLL DOWN
            if keyboard.is_pressed('n'):
                mouse.wheel(-scroll_displacement)

            # SCROLL UP
            if keyboard.is_pressed('m'):
                mouse.wheel(scroll_displacement)

            # return control to other applications for a while
            sleep(d_time)

    sleep(0.1)
Ejemplo n.º 21
0
def mouse_scroll():
    x, y = mouse.get_position()
    mouse.move(500, 250, absolute=True, duration=0)
    mouse.wheel(2)
    mouse.move(x, y, absolute=True, duration=0)
Ejemplo n.º 22
0
def wheel():
    for y in range(0, 5):
        mouse.wheel(-1)
        time.sleep(1)
Ejemplo n.º 23
0
import sys

# pos is to lef, neg to right
#

DELTA = -0.01
TIMER = 2
SPEED = .01

# 3D
# DELTA=-0.1
# TIMER=2
# SPEED=0.1

# 2D
# DELTA=-0.01
# TIMER=2
# SPEED=.01

for i in range(0, TIMER):
    print("auto mousewheel %f in %d" % (DELTA, TIMER - i))
    sys.stdout.flush()
    time.sleep(1)

print("auto mousewheel scrolling...")
sys.stdout.flush()

while (1):
    mouse.wheel(delta=DELTA)
    time.sleep(SPEED)
Ejemplo n.º 24
0
def scroll():
    delta = keys_values[Key['ScrollUp']] - keys_values[Key['ScrollDown']]
    mouse.wheel(delta)
Ejemplo n.º 25
0
 def scrollDown():
     mouse.move(10,10,absolute=False,duration=1)
     for i in range(1,LIMIT):
         mouse.wheel(-0.01)
         time.sleep(PAUSE)
         print("Down")
Ejemplo n.º 26
0
# drag from (0, 0) to (100, 100) relatively with a duration of 0.1s
mouse.drag(0, 0, 100, 100, absolute=False, duration=0.1)

# whether a button is clicked
print(mouse.is_pressed('right'))

# move 100 right & 100 down
mouse.move(100, 100, absolute=False, duration=0.2)

# make a listener when left button is clicked
mouse.on_click(lambda: print("Left Button clicked."))
# make a listener when right button is clicked
mouse.on_right_click(lambda: print("Right Button clicked."))

# remove the listeners when you want
mouse.unhook_all()

# scroll down
mouse.wheel(-1)

# scroll up
mouse.wheel(1)

# record until you click right
events = mouse.record()

# replay these events
mouse.play(events[:-1])


import numpy as np
import time
import mouse

while True:
    random_row = np.random.random_sample() * 100
    random_col = np.random.random_sample() * 10
    random_time = np.random.random_sample() * np.random.random_sample() * 100
    mouse.wheel(1000)
    mouse.wheel(-1000)
    mouse.move(random_row, random_col, absolute=False, duration=0.2)
    mouse.move(-random_row, -random_col, absolute=False, duration=0.2)
    mouse.LEFT
    time.sleep(random_time)
Ejemplo n.º 28
0
 def play(self):
     mouse.wheel(self.delta)