Пример #1
0
def Autoclicker():
    from pynput.mouse import Button, Controller

    delay = 0.01
    button = Button.left
    number_of_clicks = 500

    number_of_click = input('How many clicks?')
    number_of_clicks = int(number_of_click)
    mouse = Controller()
    begin = 1
    number_clicked = 0
    time.sleep(10)
    if begin == 1:
        while number_clicked < number_of_clicks:
            mouse.press(button)
            time.sleep(.01)
            mouse.release(button)
            time.sleep(20)
            number_clicked += 1
            if number_clicked == number_of_clicks:
                begin = 0
                exit()
Пример #2
0
class Controller:
    def __init__(self):
        self.mouse = MouseController()

    def move_mouse(self, coord):
        x = coord[0]
        y = coord[1]

        def set_mouse_position(x, y):
            self.mouse.position = (int(x), int(y))

        def smooth_move_mouse(from_x, from_y, to_x, to_y, speed=0.2):
            steps = 40
            sleep_per_step = speed // steps
            x_delta = (to_x - from_x) / steps
            y_delta = (to_y - from_y) / steps
            for step in range(steps):
                new_x = x_delta * (step + 1) + from_x
                new_y = y_delta * (step + 1) + from_y
                set_mouse_position(new_x, new_y)
                time.sleep(sleep_per_step)

        return smooth_move_mouse(self.mouse.position[0],
                                 self.mouse.position[1], x, y)

    def left_mouse_click(self):
        self.mouse.click(Button.left)

    def left_mouse_drag(self, start, end):
        self.move_mouse(*start)
        time.sleep(0.2)
        self.mouse.press(Button.left)
        time.sleep(0.2)
        self.move_mouse(*end)
        time.sleep(0.2)
        self.mouse.release(Button.left)
        time.sleep(0.2)
Пример #3
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)
Пример #4
0
class WorkerThread(QThread):
    def __init__(self):
        super().__init__()
        self.mouse = Controller()
        self.pressed = False

    def run(self):
        print("Thread working!")
        # print(threading.currentThread().getName())
        while True:
            if window.click_active:
                self.mouse.click(Button.left)
                # pyautogui.click(button='left')
                # print("clicking")
                # time.sleep(.100)
            elif window.hold_active and not self.pressed:
                self.mouse.press(Button.left)
                # print("Pressed")
                self.pressed = True
            elif self.pressed and not window.hold_active:
                self.mouse.release(Button.left)
                # print("Realsed")
                self.pressed = False
            time.sleep(.100)
Пример #5
0
def mouse_triple_left_click():
    """ 3 clics gauche de la souris pour sélectionner du texte facilement"""
    from pynput.mouse import Button, Controller
    mouse = Controller()
    mouse.press(Button.left)
    mouse.release(Button.left)
    mouse.press(Button.left)
    mouse.release(Button.left)
    mouse.press(Button.left)
    mouse.release(Button.left)
Пример #6
0
def shoot():
    mouse = Controller()
    mouse.press(Button.right)
    time.sleep(0.1)
    mouse.release(Button.right)
    time.sleep(1)
    mouse.press(Button.left)
    time.sleep(0.1)
    mouse.release(Button.left)
    mouse.move(1, 0)
    time.sleep(1)
    mouse.press(Button.right)
    time.sleep(0.1)
    mouse.release(Button.right)
    time.sleep(1)
    mouse.press(Button.left)
    time.sleep(0.1)
    mouse.release(Button.left)
Пример #7
0
 def speedUp(self, speed):
     pyautogui.click(1317, 892)
     if (speed.upper() == "LOW"):
         mouse = Controller()
         mouse.press(Button.left)
         pyautogui.dragTo(1319, 986, duration=0.3)
         mouse.release(Button.left)
     elif (speed.upper() == "MEDIUM"):
         mouse = Controller()
         mouse.press(Button.left)
         pyautogui.dragTo(1319, 832, duration=0.3)
         mouse.release(Button.left)
     elif (speed.upper() == "HIGH"):
         mouse = Controller()
         mouse.press(Button.left)
         pyautogui.dragTo(1317, 722, duration=0.3)
         mouse.release(Button.left)
     self.speed = speed
Пример #8
0
 def speedUp(self, speed):
     pyautogui.click(1231, 875)
     if (speed.upper() == "LOW"):
         mouse = Controller()
         mouse.press(Button.left)
         pyautogui.dragTo(1227, 986, duration=0.3)
         mouse.release(Button.left)
     elif (speed.upper() == "MEDIUM"):
         mouse = Controller()
         mouse.press(Button.left)
         pyautogui.dragTo(1227, 832, duration=0.3)
         mouse.release(Button.left)
     elif (speed.upper() == "HIGH"):
         mouse = Controller()
         mouse.press(Button.left)
         pyautogui.dragTo(1227, 738, duration=0.3)
         mouse.release(Button.left)
     self.speed = speed
     backToGUI()
class ClickerExecutor(object):
    def __init__(self, cash_value: int) -> None:
        self.log = logging.getLogger('clicker')
        self.log.setLevel(logging.DEBUG)
        self.log.addHandler(logging.StreamHandler())
        self.cash_value = cash_value
        self.is_fullscreen = False
        self.mouse = Controller()

    def get_mouse_position(self):
        position = self.mouse.position
        self.log.debug('The current pointer position is {0}'.format(position))
        return position

    def mouse_click(self, x, y, x_offset=0, y_offset=0, delay=0.0):
        need_position = (x + x_offset, y + y_offset)
        self.log.debug('Move mouse to {} before click'.format(need_position))
        self.mouse.position = need_position
        self.get_mouse_position()
        self.log.debug('Mouse click')
        time.sleep(0.1)
        self.mouse.press(Button.left)
        time.sleep(0.1)
        self.mouse.release(Button.left)
        time.sleep(delay)
        self.log.debug('Verify mouse after click')
        if self.get_mouse_position() != need_position:
            raise SystemExit('Exit because mouse moved')

    def clicker_process(self):
        self.log.debug('Clicker start')
        x_offset = 0  # 1920x1080
        # x_offset = 1920  # 3840x1080
        clean_position = (215, 150)
        if self.is_fullscreen:
            clean_position = (23, 23)
        self.log.debug('Activate game')
        bottle_buy_price = 85
        bottle_sell_price = 90
        sell_profit = bottle_sell_price - bottle_buy_price
        cash_value = self.cash_value
        self.log.debug('Initial cash value {}'.format(cash_value))
        if cash_value < bottle_buy_price:
            raise SystemExit(
                'Cash value less than poision bottle price {}'.format(
                    bottle_buy_price))
        self.mouse_click(*clean_position, delay=0.7, x_offset=x_offset)
        while True:
            if self.get_mouse_position() == (0, 0):
                raise SystemExit('Exit because mouse position (0, 0)')
            bottle_number = cash_value // bottle_buy_price
            self.log.debug('Poision bottles number {}'.format(bottle_number))
            cash_value += bottle_number * sell_profit
            self.log.debug('New cash value {}'.format(cash_value))
            self.hero_of_the_kingdom_trade_iteration(bottle_number)
        self.log.debug('Clicker finish')

    def hero_of_the_kingdom_trade_iteration(self, bottle_number):
        self.log.debug('Trade iteration start')
        x_offset = 0  # 1920x1080
        # x_offset = 1920  # 3840x1080
        if self.is_fullscreen:
            map_position = (75, 75)
            map_city_position = (410, 450)
            map_secret_glade_position = (1310, 145)
            bootlegger_position = (1595, 220)
            bootlegger_buy_bottle_position = (1535, 340)
            bootlegger_trade_confirm_position = (1550, 600)
            hunter_position = (485, 495)
            hunter_sell_bottle_position = (675, 465)
            hunter_trade_confirm_position = (430, 735)
        else:
            map_position = (250, 195)
            map_city_position = (525, 490)
            map_secret_glade_position = (1240, 255)
            bootlegger_position = (1470, 305)
            bootlegger_buy_bottle_position = (1415, 400)
            bootlegger_trade_confirm_position = (1430, 620)
            hunter_position = (580, 525)
            hunter_sell_bottle_position = (735, 505)
            hunter_trade_confirm_position = (535, 720)
        self.log.debug('Open map')
        self.mouse_click(*map_position, delay=2, x_offset=x_offset)
        self.log.debug('Travel to city')
        self.mouse_click(*map_city_position, delay=1.7, x_offset=x_offset)
        self.log.debug('Trade with bootlegger')
        self.mouse_click(*bootlegger_position, delay=1.7, x_offset=x_offset)
        self.log.debug('Buy {} poision bottles'.format(bottle_number))
        for i in range(bottle_number):
            self.mouse_click(*bootlegger_buy_bottle_position,
                             delay=0.5,
                             x_offset=x_offset)
        self.log.debug('Confirm trade')
        self.mouse_click(*bootlegger_trade_confirm_position,
                         delay=0.7,
                         x_offset=x_offset)
        self.log.debug('Open map')
        self.mouse_click(*map_position, delay=2, x_offset=x_offset)
        self.log.debug('Travel to glade')
        self.mouse_click(*map_secret_glade_position,
                         delay=1.7,
                         x_offset=x_offset)
        self.log.debug('Trade with hunter')
        self.mouse_click(*hunter_position, delay=1.7, x_offset=x_offset)
        self.log.debug('Sell {} poision bottles'.format(bottle_number))
        for i in range(bottle_number):
            self.mouse_click(*hunter_sell_bottle_position,
                             delay=0.5,
                             x_offset=x_offset)
        self.log.debug('Confirm trade')
        self.mouse_click(*hunter_trade_confirm_position,
                         delay=0.7,
                         x_offset=x_offset)
        self.log.debug('Trade iteration finish')
Пример #10
0
class Mouse:
    def __init__(self):
        self.mouse = Controller()
        self.human_sampler = human_input.HumanInput()
        self.paths = pickle.load(open(config.MOUSE_VECTORS_FILENAME, "rb"))
        if len(self.paths) < 3:
            print("Record some mouse paths first")
            exit(0)

    def f(self, x):
        tck = interpolate.splrep(x_points, y_points)
        return interpolate.splev(x, tck)

    def smooth_move(self, x, y, fast=False):
        # delay = self.human_sampler.get_click_interval_ms() / 1000.0
        # time.sleep(abs(delay))

        self.move_using_path(self.paths[random.randrange(len(self.paths))],
                             (x, y), fast)
        self.mouse.move(4, 4)
        self.mouse.move(-4, -4)

    def click_in_frame(self,
                       x,
                       y,
                       scroll=True,
                       right=False,
                       move_after=True,
                       fast=False):
        if y > config.MONITOR['width']:
            print(y, x)
            print("Attempted to click outside of the frame on the x-axis")
            exit(1)

        if x > config.MONITOR['height']:
            print(y, x)
            print("Attempted to click outside of the frame on the y-axis")
            exit(1)

        original_position = self.mouse.position

        # mouse.position = (y, x + top_offset)
        self.smooth_move(y + config.MONITOR['left'], x + config.MONITOR['top'],
                         fast)

        # Press and release
        if not fast:
            delay = int(human_input.sample_normal(50, 15)) / 1000.0
            time.sleep(abs(delay))

        button = Button.left if not right else Button.right
        if config.DEBUG_CLICK:
            print("[MOUSE DOWN]")
        else:
            self.mouse.press(button)

        delay = int(human_input.sample_normal(50, 15)) / 1000.0
        time.sleep(abs(delay))

        if config.DEBUG_CLICK:
            print("[MOUSE UP]")
        else:
            self.mouse.release(button)

        if move_after:
            self.move_randomly(scroll)
            self.smooth_move(original_position[1], original_position[0])

    def move_randomly(self, scroll):
        width = config.MONITOR['width']
        height = config.MONITOR['height']

        should_scroll = scroll and (random.randint(0, 2) == 0)
        if should_scroll:
            self.mouse.press(Button.middle)

        self.smooth_move(random.randrange(height), random.randrange(width))

        if should_scroll:
            self.mouse.release(Button.middle)

    def pan(self):
        width = config.MONITOR['width']
        height = config.MONITOR['height']

        starting_x = random.randrange(int(width / 3.0), int(2 * width / 3.0))
        starting_y = random.randrange(int(height / 3.0), int(2 * height / 3.0))

        ending_x = int(starting_x / 2.0) + random.randrange(
            -int(width / 6.0), int(width / 6.0))
        ending_y = random.randrange(int(height / 8.0))

        self.smooth_move(starting_x, starting_y)
        self.mouse.press(Button.middle)
        self.smooth_move(ending_x, ending_y)
        self.mouse.release(Button.middle)

    def position(self):
        print(self.mouse.position)

    def move_using_path(self, path, end, fast=False):
        start = self.mouse.position
        # Contingent on recorded paths having an l2 length of sqrt(2) since they go from (0, 0) to (1, 1)

        target = (end[0] - start[0], end[1] - start[1])
        rotate_counter = target[1] < target[0]
        scale_factor = vector.l2_length(target) / math.sqrt(2)
        scale = np.eye(2) * scale_factor

        theta = vector.angle_between(target, (10.0, 10.0))
        if rotate_counter:
            theta = -theta

        c, s = np.cos(theta), np.sin(theta)
        rotate = np.array(((c, -s), (s, c)))

        pause = 0.01 if fast else 0.02
        for point in path:
            point_vector = [[point[0]], [point[1]]]
            transformed_point = scale.dot(rotate).dot(point_vector)
            x = int(transformed_point[0][0] + start[0])
            y = int(transformed_point[1][0] + start[1])
            self.mouse.position = (x, y)
            time.sleep(pause)

        self.mouse.position = end
Пример #11
0
def mouse_click():
    mouse = Controller()
    # 点击按钮
    mouse.press(Button.left)
    # 释放按钮
    mouse.release(Button.left)
mouse = Controller()
try:
    ser = serial.Serial(
        'COM7', baudrate=115200)  # Setting Serial port number and baudrate
    while 1:  # While loop to continuesly scan and read data from serial port and execute
        dump = ser.readline()  # Reading Serial port
        dump = str(dump)  # Converting byte data into string
        dump = dump[2:-5]  # Cleaning up the raw data recieved from serial port
        data = dump.split(
            ','
        )  # Spliting up the data to individual items in a list. the first item being the data identifier
        print(data)
        if data[0] == "DATAL":  # Checking if the identifier is "DATAL" which the Arduino sends the data as the gyro X, Y and Z values
            mouse.move(
                int(data[1]), int(data[2])
            )  # Moving the mouse by using the X and Y values after converting them into integer

        if data[0] == "DATAB":  # Checking if the identifier is "DATAB" which the Arduino sends the values for Left/Right button
            if data[1] == 'L':  # If the Left button is pressed
                mouse.press(
                    Button.left
                )  # The corresponding button is pressed and released
                mouse.release(Button.left)
            if data[1] == 'R':  # If the Right button is pressed
                mouse.press(
                    Button.right
                )  # The corresponding button is pressed and released
                mouse.release(Button.right)
except:
    print("Mouse not found or disconnected.")
    k = input("Press any key to exit.")
Пример #13
0
import time

mouse = Controller()


def countdown():
    print("pressing button in 3...")
    time.sleep(1)
    print("                   2...")
    time.sleep(1)
    print("                   1...")
    time.sleep(1)
    return


while True:
    x = input("Press 1, 2 or 3 for left, right, or middle click: ")
    countdown()
    if x == "1":
        mouse.press(Button.left)
        time.sleep(1)
        mouse.release(Button.left)
    elif x == "2":
        mouse.press(Button.right)
        time.sleep(1)
        mouse.release(Button.right)
    elif x == "3":
        mouse.press(Button.middle)
        time.sleep(1)
        mouse.release(Button.middle)
Пример #14
0
STOP = TOGGLE = False


def on_press(key):
    global STOP, TOGGLE
    if key == TOGGLE_KEY:
        if TOGGLE:
            TOGGLE = False
            print("[PyClicker] Toggled PyClicker - OFF")
        else:
            TOGGLE = True
            print("[PyClicker] Toggled PyClicker - ON")
    elif key == END_KEY:
        STOP = True
        print("[PyClicker] Exiting")


if __name__ == "__main__":
    listener = Listener(on_press=on_press)
    listener.start()
    mouse = Controller()

    print(f"[PyClicker] - Press {TOGGLE_KEY} to toggle PyClicker on or off.")
    print(f"[PyClicker] - Press {END_KEY} to stop PyClicker.")
    while not STOP:
        if TOGGLE:
            mouse.press(MOUSE_BUTTON)
            mouse.release(MOUSE_BUTTON)
            time.sleep(DELAY)
    listener.stop()
Пример #15
0
class Solver(object):
    def __init__(self, recognizer: Recognizer, analyzer: Analyzer, mines):
        self.analyzer = analyzer
        self.recognizer = recognizer
        self.mines = mines
        self.minesRemaining = mines
        self.mouse = Controller()
        self.badTileEncountered = False
        self.actionTaken = False

    def solve(self, shouldContinue):
        # Click middle of screen to get started
        self._click(int(self.analyzer.width / 2),
                    int(self.analyzer.height / 2))
        self.recognizer.printUpdatedBoard()
        self.solveLoop(shouldContinue)
        #self.recognizer.printUpdatedBoard()
        print("All done!" if not self.badTileEncountered else "Whoops...")
        self.recognizer.printUpdatedBoard()

    def solveLoop(self, shouldContinue):
        while True:
            self.actionTaken = False
            for y in range(self.analyzer.height):
                for x in range(self.analyzer.width):
                    if (self.badTileEncountered or not shouldContinue()):
                        return
                    # Find data
                    tileNum = self.analyzer.getTileNumber(x, y)
                    surroundingUnknownIndicies = self.analyzer.getIndiciesOfSurroundingVarient(
                        x, y, -1)
                    numOfSurroundingFlags = len(
                        self.analyzer.getIndiciesOfSurroundingVarient(
                            x, y, 'F'))
                    # Run actual algorithms
                    self._definiteFlag(x, y, tileNum,
                                       surroundingUnknownIndicies,
                                       numOfSurroundingFlags)
                    self._definiteClick(x, y, tileNum,
                                        surroundingUnknownIndicies,
                                        numOfSurroundingFlags)
            #self._checkForPatterns()
            if not self.actionTaken: return

    def _click(self, x, y, right=False):
        self.actionTaken = True
        self._point(x, y)
        self.mouse.press(Button.left if right == False else Button.right)
        time.sleep(0.1)
        self.mouse.release(Button.left if right == False else Button.right)
        # If flag placed, add to count
        if right: self.minesRemaining -= 1
        # Sleep a little to give the board a chance to update
        time.sleep(0.1)
        self.recognizer.updateGrid()
        # Check for bad tile
        if (not right and self.analyzer.getTileChar(x, y) == 'B') or \
           (self.analyzer.getNumberOfSurroundingVarient(x, y, 'L') > 0):
            self.badTileEncountered = True

    def _point(self, x, y):
        if (not self.analyzer.tileInGrid(x, y)):
            raise Exception("_click called on non-existant tile")
        self.mouse.position = self.analyzer.recognizer.getTileCenter(x, y)

    # Specific solving algorithms
    def _definiteFlag(self, x, y, tileNum, surroundingUnknownIndicies,
                      numOfSurroundingFlags):
        if (tileNum > 0 and (tileNum == len(surroundingUnknownIndicies) +
                             numOfSurroundingFlags)):
            for indicies in surroundingUnknownIndicies:
                self._click(indicies[0], indicies[1], right=True)

    def _definiteClick(self, x, y, tileNum, surroundingUnknownIndicies,
                       numOfSurroundingFlags):
        if (tileNum > 0 and (tileNum == numOfSurroundingFlags)):
            for indicies in surroundingUnknownIndicies:
                self._click(indicies[0], indicies[1])
Пример #16
0
    def __init__(self, image, faceCoordinates):
        if MODE == "BROWSING":
            self.offsetHolder = gamingOffset
        else:
            self.offsetHolder = browsingOffset
        (left, top, w, h, leftEye, rightEye, noseTopPosition,
         noseBottomPosition, noseLeftPixel, noseRightPixel) = faceCoordinates

        cv2.circle(image, (left, top), 3, (0, 255, 0), 4)
        for (x, y) in faceCoordinates[4:]:
            cv2.circle(image, (x, y), 2, (255, 0, 0), 3)
        # cv2.imshow("Image 2", image)
        mouse = Controller()
        # This function gets the facial coordinates, and the input image, and makes the necessary calculations.
        distanceLeft = np.array(noseTopPosition - leftEye)
        unitLeft = distanceLeft
        distanceRight = np.array(noseTopPosition - rightEye)
        unitRight = distanceRight
        distanceLeft = np.sum(distanceLeft**2, axis=0)
        distanceRight = np.sum(distanceRight**2, axis=0)
        unitLeft = unitLeft / distanceLeft**0.5
        unitRight = unitRight / distanceRight**0.5
        angle = np.dot(unitLeft, unitRight)
        angle = math.degrees(math.acos(angle))
        angle = (angle // 2) * 10
        topBottom = np.array(noseTopPosition - noseBottomPosition)
        topBottom = (np.sum(topBottom**2, axis=0))**0.5
        # Face top/bottom tracking using angle.

        faceRatio = topBottom / h
        val = (distanceLeft - distanceRight)
        global prevCursor, beginTime, dblTime
        x, y = mouse.position
        if (x, y) == prevCursor:
            if (time.time() - beginTime) > 2:
                mouse.press(Button.left)
                mouse.release(Button.left)
                print("Click event occured")
                beginTime = time.time()

            if (time.time() - dblTime) > 4:
                mouse.click(Button.left, 2)
                print("Double click event occured")
                dblTime = time.time()
        else:
            beginTime = time.time()
            dblTime = time.time()
            prevCursor = mouse.position
        if abs(val) > 300:
            if distanceLeft > distanceRight:  #Facing right
                x = x + self.offsetHolder['x']
            else:
                x = x - self.offsetHolder['x']  # Facing left

        if angle not in range(760, 840):
            if angle <= 760:
                y = y - self.offsetHolder['y']
            else:
                y = y + self.offsetHolder['y']

        mouse.position = x, y
Пример #17
0
def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold,
                mode):
    """Loop forever and map evdev events to mouse

    Args:
        rm_inputs (dictionary of paramiko.ChannelFile): dict of pen, button
            and touch input streams
        orientation (str): tablet orientation
        monitor_num (int): monitor number to map to
        region (boolean): whether to selection mapping region with region tool
        threshold (int): pressure threshold
        mode (str): mapping mode
    """

    from pynput.mouse import Button, Controller

    lifted = True
    new_x = new_y = False

    mouse = Controller()

    monitor = get_monitor(monitor_num, region, orientation)
    log.debug('Chose monitor: {}'.format(monitor))

    while True:
        _, _, e_type, e_code, e_value = struct.unpack(
            '2IHHi', rm_inputs['pen'].read(16))

        if e_type == e_type_abs:

            # handle x direction
            if e_code == e_code_stylus_xpos:
                log.debug(e_value)
                x = e_value
                new_x = True

            # handle y direction
            if e_code == e_code_stylus_ypos:
                log.debug('\t{}'.format(e_value))
                y = e_value
                new_y = True

            # handle draw
            if e_code == e_code_stylus_pressure:
                log.debug('\t\t{}'.format(e_value))
                if e_value > threshold:
                    if lifted:
                        log.debug('PRESS')
                        lifted = False
                        mouse.press(Button.left)
                else:
                    if not lifted:
                        log.debug('RELEASE')
                        lifted = True
                        mouse.release(Button.left)

            # only move when x and y are updated for smoother mouse
            if new_x and new_y:
                mapped_x, mapped_y = remap(x, y, wacom_width, wacom_height,
                                           monitor.width, monitor.height, mode,
                                           orientation)
                mouse.move(monitor.x + mapped_x - mouse.position[0],
                           monitor.y + mapped_y - mouse.position[1])
                new_x = new_y = False
Пример #18
0
passme = True
pyn = Controller()
print("What is the time gap between each click (Can be a decimal)")
num = float(input())
print("Press S To Start and W To Stop")

print(num)


def check():
    if keyboard.is_pressed('w'):
        print("Quiting...")
        sleep(3)
        quit()


while True:
    if keyboard.is_pressed('s'):
        print("Starting...")
        sleep(1)
        for i in range(1, 10000):
            check()
            sleep(num)
            check()
            pyn.press(Button.left)
            pyn.release(Button.left)
            check()
            print(i)
            check()
Пример #19
0
from pynput.mouse import Button, Controller
from pynput.keyboard import Listener, KeyCode

#init
delay = float(input("delay(s) :"))
print("\ndelay = " + str(delay))

button = Button.left
mouse = Controller()
click = int(0)
start = int(1)

while True:
    if start == 0:
        if click == 1:
            click = 0
            print(str(click))

    elif start == 1:        
        if click == 0:
            click = 1
            print(str(click))
        
    elif click == 1:
        mouse.press(button)
        mouse.release(button)
        time.sleep(delay)
    
    else :
        print(' ')
Пример #20
0
class Controller:
    # ------------------------------------------------------------------------------------------------------------------
    # Const vars
    # Cursor
    _CENTER_POS = (960, 540)
    _ROTATE_SPEED_X = 4.47
    _ROTATE_SPEED_Y = 6.8
    _ROTATE_STEP = 10

    # General
    _CONTROL_DELAY = 0.02

    def __init__(self):
        self.keyboard = KeyboardController()
        self.cursor = MouseController()

        self.loadedTemplates = {}
        self.currentPressedButtons = []

    # ------------------------------------------------------------------------------------------------------------------
    # Public methods
    def Forward(self):
        self.cursor.press(Button.left)
        self.cursor.press(Button.right)
        self.currentPressedButtons.append(Button.left)
        self.currentPressedButtons.append(Button.right)

    def Stop(self):
        for keycode in self.currentPressedButtons:
            if keycode in [Button.left, Button.right, Button.middle]:
                self.cursor.release(keycode)
            else:
                self.keyboard.release(keycode)
        time.sleep(Controller._CONTROL_DELAY)

    def Click(self, position):
        self.cursor.position = int(position[0]), int(position[1])
        time.sleep(Controller._CONTROL_DELAY)
        self.cursor.press(Button.left)
        time.sleep(Controller._CONTROL_DELAY)
        self.cursor.release(Button.left)

    def Scroll(self, amp):
        self.cursor.scroll(0, amp)

    def Rotate(self, angX, angY):
        self.cursor.position = Controller._CENTER_POS
        self.cursor.press(Button.left)
        currentAngX = abs(angX)
        currentAngY = abs(angY)
        modX = 1 if angX >= 0 else -1
        modY = 1 if angY >= 0 else -1
        while (currentAngX > 0) or (currentAngY > 0):
            # Find step by X and Y axis
            stepX = Controller._ROTATE_STEP if currentAngX >= Controller._ROTATE_STEP else currentAngX
            currentAngX -= stepX
            stepY = Controller._ROTATE_STEP if currentAngY >= Controller._ROTATE_STEP else currentAngY
            currentAngY -= stepY
            time.sleep(Controller._CONTROL_DELAY)
            pos = Controller._CENTER_POS
            newPos = (int(pos[0] + modX * Controller._ROTATE_SPEED_X * stepX),
                      int(pos[1] + modY * Controller._ROTATE_SPEED_Y * stepY))
            self.cursor.position = newPos
            time.sleep(Controller._CONTROL_DELAY)
        self.cursor.release(Button.left)
        time.sleep(Controller._CONTROL_DELAY)

    def FirstPerson(self):
        self.Rotate(0, 180)
        self.Rotate(0, -80)
        for _ in range(30):
            self.Scroll(10)
            time.sleep(Controller._CONTROL_DELAY)

    # ------------------------------------------------------------------------------------------------------------------
    # Private methods
    def _PressKeyboard(self, keycode):
        self.keyboard.press(keycode)
        time.sleep(Controller._CONTROL_DELAY)
Пример #21
0
def main():

    time.sleep(2)

    mouse = Controller()
    posLoL = win32gui.EnumWindows(callback, None)

    #Check if league client exsists
    while leagueSize[0] > 0 and leagueSize[1] > 0:

        posLoL = win32gui.EnumWindows(callback, None)

        mouse.position = (leagueSize[0] / 2 - 250, leagueSize[1] / 2 + 200
                          )  #Set offset
        keyboard.release("f2")
        keyboard.press("f2")

        mouse.press(Button.right)  #Click so I move to the position

        healtMex, healtMey = 680, 1045
        manaMex, manaMey = 680, 1064
        healtAlly1x, healtAlly1y = 1670, 780
        healtAlly2x, healtAlly2y = 1735, 780
        healtAlly3x, healtAlly3y = 1800, 780
        healtAlly4x, healtAlly4y = 1864, 780

        healtMe = [
            leaguePos[0] + healtMex, leaguePos[1] + healtMey,
            leaguePos[0] + healtMex + 416, leaguePos[1] + healtMey + 1
        ]
        manaMe = [
            leaguePos[0] + manaMex, leaguePos[1] + manaMey,
            leaguePos[0] + manaMex + 416, leaguePos[1] + manaMey + 1
        ]
        healtAlly1 = [
            leaguePos[0] + healtAlly1x, leaguePos[1] + healtAlly1y,
            leaguePos[0] + healtAlly1x + 47, leaguePos[1] + healtAlly1y + 1
        ]
        healtAlly2 = [
            leaguePos[0] + healtAlly2x, leaguePos[1] + healtAlly2y,
            leaguePos[0] + healtAlly2x + 47, leaguePos[1] + healtAlly2y + 1
        ]
        healtAlly3 = [
            leaguePos[0] + healtAlly3x, leaguePos[1] + healtAlly3y,
            leaguePos[0] + healtAlly3x + 47, leaguePos[1] + healtAlly3y + 1
        ]
        healtAlly4 = [
            leaguePos[0] + healtAlly4x, leaguePos[1] + healtAlly4y,
            leaguePos[0] + healtAlly4x + 47, leaguePos[1] + healtAlly4y + 1
        ]

        # # health = getInfo(healtMe)
        # # mana = getInfo(manaMe)

        deathAlly1 = [
            leaguePos[0] + healtAlly1x, leaguePos[1] + healtAlly1y + 11,
            leaguePos[0] + healtAlly1x + 1, leaguePos[1] + healtAlly1y + 1 + 11
        ]
        deathAlly2 = [
            leaguePos[0] + healtAlly2x, leaguePos[1] + healtAlly2y + 11,
            leaguePos[0] + healtAlly2x + 1, leaguePos[1] + healtAlly2y + 1 + 11
        ]
        deathAlly3 = [
            leaguePos[0] + healtAlly3x, leaguePos[1] + healtAlly3y + 11,
            leaguePos[0] + healtAlly3x + 1, leaguePos[1] + healtAlly3y + 1 + 11
        ]
        deathAlly4 = [
            leaguePos[0] + healtAlly4x, leaguePos[1] + healtAlly4y + 11,
            leaguePos[0] + healtAlly4x + 1, leaguePos[1] + healtAlly4y + 1 + 11
        ]

        #Check ally healts

        if not isDead(deathAlly1):
            if getInfo(healtAlly1) < 75:
                print("Healing ally 1")
                mouse.release(Button.right)
                mouse.position = (leagueSize[0] / 2, leagueSize[1] / 2)
                time.sleep(0.2)
                keyboard.press("s")
                time.sleep(0.2)
                mouse.click(Button.left, 1)
                time.sleep(0.2)
                keyboard.release("s")
        else:
            keyboard.press_and_release("b")

        mouse.position = (leagueSize[0] / 2 - 250, leagueSize[1] / 2 + 200
                          )  #Set offset
        mouse.press(Button.right)  #Click so I move to the position

        if not isDead(deathAlly4) or not isDead(deathAlly3) or not isDead(
                deathAlly2) or not isDead(deathAlly1):
            if getInfo(healtAlly1) < 25 or getInfo(healtAlly2) < 25 or getInfo(
                    healtAlly3) < 25 or getInfo(healtAlly4) < 25:
                print("Ulting every champ")
                keyboard.press_and_release("f")
                time.sleep(0.2)

        time.sleep(3)
        mouse.release(Button.right)

        #print(health, mana)
        #print(healthAllyOne, healthAllyTwo, healthAllyThre, healthAllyFour)

    else:
        print("Lol finished, go on to next step")
Пример #22
0
class Mouse(object):
    def __init__(self, image_size):
        self.monitor = get_monitors()[0]
        self.image_size = [image_size[0] - 50, image_size[1] - 50]
        self.image_height = self.image_size[0]
        self.image_width = self.image_size[1]
        self.x_relation = self.monitor.width / self.image_width
        self.y_relation = self.monitor.height / self.image_height
        self.mouse = Controller()
        self.is_left_pressed = False

    def update_view_size(self, image_size):
        if self.image_size != [image_size[0] - 50, image_size[1] - 50]:
            self.image_size = [image_size[0] - 50, image_size[1] - 50]

    def move(self, move_delta):
        x = self.mouse.position[0] + move_delta[0] * self.x_relation
        y = self.mouse.position[1] + move_delta[1] * self.y_relation
        self.mouse.position = (x, y)

    def right_click(self):
        pass

    def left_click(self):
        if not self.is_left_pressed:
            self.is_left_pressed = True
            self.mouse.press(Button.left)

    def release_all(self):
        self.is_left_pressed = False
        self.mouse.release(Button.left)

    def search_trigger(self, move_stats, move_cap, move_delta):
        if move_delta is None:
            move_delta = self.mouse.position

        if move_stats[0] >= move_cap:
            self.release_all()
        if move_stats[1] >= move_cap:
            self.move(move_delta)
            # self.move_mouse(center[0], center[1])
        # if move_stats[3] >= move_cap:
        #     self.release_all()
        if move_stats[4] >= move_cap:
            self.left_click()

    def move_mouse(self, x, y):
        def set_mouse_position(x, y):
            self.mouse.position = (int(x), int(y))

        def smooth_move_mouse(from_x, from_y, to_x, to_y, speed=0.1):
            steps = 40
            sleep_per_step = speed // steps
            x_delta = (to_x - from_x) / steps
            y_delta = (to_y - from_y) / steps
            for step in range(steps):
                new_x = x_delta * (step + 1) + from_x
                new_y = y_delta * (step + 1) + from_y
                set_mouse_position(new_x, new_y)
                time.sleep(sleep_per_step)

        return smooth_move_mouse(self.mouse.position[0],
                                 self.mouse.position[1], x * self.x_relation,
                                 y * self.y_relation)
Пример #23
0
def mouse_click():
    mouse = Controller()
    mouse.press(Button.left)
    mouse.release(Button.left)
    "!play hate u",
]

time.sleep(7)
for i in range(len(l) - 1):

    mouse.position = (954, 627)
    time.sleep(1)
    mouse.position = (1078, 590)
    mouse.click(Button.left, 1)
    time.sleep(1)
    mouse.position = (943, 689)
    time.sleep(1)
    mouse.click(Button.left, 1)
    time.sleep(1)
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
    time.sleep(2)

    keyboard.type(l[i])
    time.sleep(1)
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
    time.sleep(60)

    keyboard.type("skip")
    time.sleep(60)
    keyboard.type("!skip")
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
    time.sleep(2)
Пример #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
        x2,y2,w2,h2=cv2.boundingRect(conts[1])
        cv2.rectangle(img,(x1,y1),(x1+w1,y1+h1),(255,0,0),2)
        cv2.rectangle(img,(x2,y2),(x2+w2,y2+h2),(255,0,0),2)
        cx1=x1+w1//2

        cy1=y1+h1//2
        cx2=x2+w2//2
        cy2=y2+h2//2
        cx=(cx1+cx2)//2
        cy=(cy1+cy2)//2
        cv2.line(img, (cx1,cy1),(cx2,cy2),(255,0,0),2)
        cv2.circle(img, (cx,cy),2,(0,0,255),2)
        mouseLoc=(sx-(cx*sx//camx), cy*sy//camy)
        wand.position=mouseLoc
        while wand.position!=mouseLoc:
            pass
    elif(len(conts)==1):
        x,y,w,h=cv2.boundingRect(conts[0])
        if(pinchFlag==0):
            wand.press(Button.left)
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        cx=x+w//2
        cy=y+h//2
        cv2.circle(img,(cx,cy),(w+h)//4,(0,0,255),2)
        mouseLoc=(sx-(cx*sx//camx), cy*sy//camy)
        wand.position=mouseLoc
        while wand.position!=mouseLoc:
            pass
    cv2.imshow("Wand1supra",img)
    cv2.waitKey(5)
Пример #27
0
 def unlock(self):
     pyautogui.moveTo(687, 533, duration=0)
     mouse = Controller()
     mouse.press(Button.left)
     pyautogui.dragTo(1200, 533, duration=0.5)
     mouse.release(Button.left)
Пример #28
0
class KeyboardMouse(threading.Thread):
    def __init__(self, logger, commonCfg):
        super(KeyboardMouse, self).__init__()

        self.__logger = logger
        self._LoadCommonParams(commonCfg)
        self.__lastFrameTime = time.time()

        # Input event queue
        self.__inputEventQueue = queue.Queue()
        #self.__inputEventQueueMutex = threading.Lock()

        self._CreateEventDict()

        # Create listener
        self.__keyboardListenerTH = threading.Thread(
            target=self._KeyBoardListener, args=())

        # short key state
        self._InitShortKeyState()

        # Create Mouse controller
        self.__mouse = Controller()

    def _InitShortKeyState(self):
        self.__keyBoardMutex = threading.Lock()
        self.__bRunningController = False
        self.__bLCtrlPress = False

    def _SetLCtrlState(self, bPress):
        self.__keyBoardMutex.acquire()
        self.__bLCtrlPress = bPress
        self.__keyBoardMutex.release()

    # L-Ctrl + 'r' : run controller
    # L-Ctrl + 'p' : pause controller
    def _SetRunningFlag(self, key):
        if self.__bLCtrlPress is False:
            return

        self.__keyBoardMutex.acquire()
        if key.char == 'R' or key.char == 'r':
            self.__bRunningController = True
        elif key.char == 'P' or key.char == 'p':
            self.__bRunningController = False
        self.__keyBoardMutex.release()

    def IsRunning(self):
        self.__keyBoardMutex.acquire()
        bRunning = self.__bRunningController
        self.__keyBoardMutex.release()
        return bRunning

    def _LoadCommonParams(self, commonCfg):
        self.__commonCfg = commonCfg

    def _Sleep(self):
        timeNow = time.time()
        timePassed = timeNow - self.__lastFrameTime
        if timePassed < self.__commonCfg.timePerFrame:
            timeDelay = self.__commonCfg.timePerFrame - timePassed
            time.sleep(timeDelay)

        self.__lastFrameTime = timeNow

    def PushEvent(self, inputEvent):
        #self.__inputEventQueueMutex.acquire()
        self.__inputEventQueue.put(inputEvent)
        #self.__inputEventQueueMutex.release()

    def PopEvent(self):
        #self.__inputEventQueueMutex.acquire()
        inputEvent = self.__inputEventQueue.get()
        #self.__inputEventQueueMutex.release()
        return inputEvent

    def _CreateEventDict(self):
        self.__eventDic = {}
        self.__eventDic[EVENT_MOUSE] = 'mouse'
        self.__eventDic[EVENT_MOUSE_RIGHT_CLICK] = 'mouse_right_click'
        self.__eventDic[EVENT_MOUSE_LEFT_CLICK] = 'mouse_left_click'
        self.__eventDic[EVENT_MOUSE_RIGHT_DCLICK] = 'mouse_right_dclick'
        self.__eventDic[EVENT_MOUSE_LEFT_DCLICK] = 'mouse_left_dclick'
        self.__eventDic[EVENT_KEYBOARD] = 'key'
        self.__eventDic[EVENT_KEYBOARD_CHAR] = 'key_char'
        self.__eventDic[EVENT_KEYBOARD_ALT_CHAR] = 'key_alt_char'
        self.__eventDic[EVENT_KEYBOARD_CTRL_CHAR] = 'key_ctrl_char'

    def _GetEventName(self, eventType):
        return self.__eventDic[eventType]

    def OnPress(self, key):
        try:
            self.__logger.info('alphanumeric key  {0} pressed'.format(
                key.char))
            self._SetRunningFlag(key)
        except AttributeError:
            self.__logger.info('special key {0} pressed'.format(key))
            if key == keyboard.Key.ctrl_l:
                self._SetLCtrlState(True)

    def OnRelease(self, key):
        try:
            self.__logger.info('{0} released'.format(key))
        except AttributeError:
            if key == keyboard.Key.ctrl_l:
                self._SetLCtrlState(False)

            if key == keyboard.Key.esc:
                return False

    def _KeyBoardListener(self):
        while True:
            with keyboard.Listener(on_press=self.OnPress,
                                   on_release=self.OnRelease) as listener:
                listener.join()

    def _ExecuteInputEvent(self, inputEvent):
        if inputEvent.eventType == EVENT_MOUSE:
            self._ExecuteMouseEvent(inputEvent)
        elif inputEvent.eventType == EVENT_KEYBOARD:
            self._ExecuteKeyboardEvent(inputEvent)

    # Before executing mouse event we should record current mouse position.
    # After executing mouse event, we should move mouse pointer to original position.
    def _ExecuteMouseEvent(self, inputEvent):
        lastPos = self.__mouse.position

        self.__mouse.position = (inputEvent.mouseX, inputEvent.mouseY)
        if inputEvent.mouseInput == EVENT_MOUSE_LEFT_CLICK:
            self.__mouse.press(Button.left)
            self.__mouse.release(Button.left)

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

        # #Double click
        # mouse.click(Button.left, 1)

        # #scroll two  steps down
        # mouse.scroll(0, 500)

        # Sleep after executing event.
        time.sleep(inputEvent.sleep)

        # After executing mouse event, we move mouse pointer to original position.

        if inputEvent.bBack is True:
            self.__mouse.position = lastPos
            self.__mouse.press(Button.left)
            self.__mouse.release(Button.left)
        return

    def _ExecuteKeyboardEvent(self, inputEvent):
        return

    def run(self):
        self.__keyboardListenerTH.start()

        while True:
            inputEvent = self.PopEvent()
            # self.__logger.info("Event: {0}".format(self._GetEventName(inputEvent.eventType)))
            self._ExecuteInputEvent(inputEvent)
            self._Sleep()
Пример #29
0
from pynput.mouse import Button, Controller as MouseController

import time

mouse = MouseController()

# In the future would have to code in the path breaks

time.sleep(1)

#========================================================
# Level 1
#=========================================================

mouse.position = (1474, 361)
mouse.press(Button.left)
time.sleep(.05)
mouse.position = (1477, 426)
mouse.release(Button.left)
mouse.press(Button.left)
time.sleep(.05)
mouse.position = (1487, 494)
mouse.release(Button.left)
mouse.press(Button.left)
time.sleep(.05)
mouse.position = (1481, 613)
mouse.release(Button.left)

time.sleep(.05)

mouse.position = (1481, 676)
Пример #30
0
def main():
    # mouse object
    mouse = Controller()
    # screen size
    screenWidth, screenHeight = (NSScreen.mainScreen().frame().size.width, NSScreen.mainScreen().frame().size.height)
    # open camera
    cam = cv2.VideoCapture(0)
    # gesture
    pinching = False

    while cam.isOpened():
        ret, img = cam.read()
        img = cv2.resize(img,(340,220))
        img = cv2.flip(img, flipCode=1)

        # convert BGR to HSV
        imgHSV = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
        # create the Mask
        mask = cv2.inRange(imgHSV,lowerBound,upperBound)
        # masks
        maskOpen = cv2.morphologyEx(mask,cv2.MORPH_OPEN,kernelOpen)
        maskClose = cv2.morphologyEx(maskOpen,cv2.MORPH_CLOSE,kernelClose)
        # use masks to find finger(s)
        maskFinal = maskClose
        matches = cv2.findContours(maskFinal.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)[1]

        if len(matches) == 2:
            if pinching:
                pinching = False
                mouse.release(Button.left)
            # blue rectangles on each finger
            x1,y1,w1,h1=cv2.boundingRect(matches[0])
            x2,y2,w2,h2=cv2.boundingRect(matches[1])
            cv2.rectangle(img,(x1,y1),(x1+w1,y1+h1),blue,2)
            cv2.rectangle(img,(x2,y2),(x2+w2,y2+h2),blue,2)
            # center of rectangles
            cx1, cy1 = coordinates(x1, y1, w1, h1)
            cx2, cy2 = coordinates(x2, y2, w2, h2)
            # midpoint between 2 fingers
            cx, cy = midpoint(cx1, cy1, cx2, cy2)
            # line connecting 2 fingers
            cv2.line(img, (cx1,cy1), (cx2,cy2), blue, 2)
            # circle at midpoint
            cv2.circle(img, (cx,cy), 2, red, 2)
            # move mouse based on circle coordinate
            moveMouse(cx, cy, screenWidth, screenHeight, camx, camy, mouse)

        elif(len(matches)==1):
            x,y,w,h=cv2.boundingRect(matches[0])
            if not pinching:
                pinching = True
                mouse.press(Button.left)
            # blue rectangle on finger
            cv2.rectangle(img,(x,y),(x+w,y+h),blue,2)
            # center of rectangle
            cx, cy = coordinates(x,y,w,h)
            # circle around center
            cv2.circle(img,(cx,cy),int((w+h)/4),red,2)
            # move mouse based on circle coordinate
            moveMouse(cx, cy, screenWidth, screenHeight, camx, camy, mouse)

        # display camera preview
        cv2.imshow("Gesture Recognition Preview", img)
        # stop program when q is pressed
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cam.release()
    cv2.destroyAllWindows()