Example #1
0
def moveIt():
    global count
    count = count + 1

    # Get time
    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")

    currentPos = mouse.position  # save current position of mouse!
    mouse.position = (
        2, 700)  # move it to the left of the screen somewhere in the middle!

    time.sleep(0.1)  # Wait a bit...
    mouse.move(5, 5)

    time.sleep(0.1)  # Wait again...
    mouse.click(button.right, 1)  # make a right click!

    time.sleep(0.1)  # Wait...
    mouse.position = (int(currentPos[0]), int(currentPos[1])
                      )  #move mouse back to where it was!
    print("Count:", count, "Mouse moved at:", current_time)

    # # Keyboard action
    # time.sleep(0.1)
    # with keyboard.pressed(key.cmd):
    #     keyboard.press(key.tab)

    # wait before click again...
    time.sleep(120)
def init_listen_to_movement(startingPosition=[50, 50], channel=1):
    x_coordinate, y_coordinate = startingPosition
    mouse.move(x_coordinate, y_coordinate)
    new_x = currentDMX[channel]
    new_y = 0

    def listen_to_movement(event):
        nonlocal new_x, new_y
        if isinstance(event, mouse._mouse_event.ButtonEvent):
            print('buttonevent', listen_to_movement)
            mouse.unhook(listen_to_movement)
            # print('unhooked')
        x, y = mouse.get_position()
        if x > x_coordinate:
            new_x += 3
            print('right', x, new_x)
        elif x < x_coordinate:
            new_x -= 3
            print('left', x, new_x)
        if y > y_coordinate:
            new_y -= 3
            print('down', y, new_y)
        elif y < y_coordinate:
            new_y += 3
            print('up', y, new_y)
        mouse.move(x_coordinate, y_coordinate)
        fade([channel, new_y, 0, 'linear'])
        eel.change_intensity((new_x, new_y))
        return new_x, new_y

    mouse.hook(listen_to_movement)
    return


# colour fade resource: https://www.sparkfun.com/news/2844
def mouseMov(timeModifier = float(1)):
    try:
        newTime = 0
        try:
            newPosition = log1.mouseLogs[0][0]
            mouse.position = newPosition
            print("PLAYING")
            for i in log1.mouseLogs:
                sleep((i[1]-newTime)*timeModifier)

                new = termWiseMinus(i[0],newPosition)
                mouse.move(*new)

                newPosition = i[0]
                newTime = i[1]
        except IndexError:
            pass
 def listen_to_movement(event):
     nonlocal new_x, new_y
     if isinstance(event, mouse._mouse_event.ButtonEvent):
         print('buttonevent', listen_to_movement)
         mouse.unhook(listen_to_movement)
         # print('unhooked')
     x, y = mouse.get_position()
     if x > x_coordinate:
         new_x += 3
         print('right', x, new_x)
     elif x < x_coordinate:
         new_x -= 3
         print('left', x, new_x)
     if y > y_coordinate:
         new_y -= 3
         print('down', y, new_y)
     elif y < y_coordinate:
         new_y += 3
         print('up', y, new_y)
     mouse.move(x_coordinate, y_coordinate)
     fade([channel, new_y, 0, 'linear'])
     eel.change_intensity((new_x, new_y))
     return new_x, new_y
from pynput import mouse

mouse = Controller()

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

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

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

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

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

# Scroll two steps down
mouse.scroll(0, 2)
Example #6
0
 def relative_move(self, width, height):
     """not implemented from pseudolanguage"""
     mouse.move(width, height)
Example #7
0
            keyboard.release(Key.control)
            sprint_toggled = True

        if mph == 0:
            if walk_toggled:  # Untoggle walk
                keyboard.press('w')
                keyboard.release('w')

            if sprint_toggled:  # Untoggle sprint
                keyboard.press(Key.control)
                keyboard.release(Key.control)
        # Joystick
        if joystickXY[0] != 1 and joystickXY[
                1] != 1:  # The farther you move away from the middle of the joystick, the higher speed the mouse goes
            if joystickXY[0] <= 128:
                mouse.move(5, 0)
            if joystickXY[1] <= 128:
                mouse.move(0, 5)

            if joystickXY[0] > 128 and joystickXY[0] <= 384:
                mouse.move(10, 0)
            if joystickXY[1] > 128 and joystickXY[1] <= 384:
                mouse.move(0, 10)
            if joystickXY[0] > 384:
                mouse.move(20, 0)
            if joystickXY[1] > 384:
                mouse.move(0, 20)

        if GPIO.input(attack) == GPIO.HIGH:  # Attack button pressed
            mouse.click(mouse.Button.left)
Example #8
0
                print("Button 'LB' was pressed.")
            if event.button == 5:
                print("Button 'RB' was pressed.")
            if event.button == 10:
                print("Button 'LT' was pressed.")
            if event.button == 8:
                print("Button 'RT' was pressed.")
            if event.button == 6:
                print("Button 'Back' was pressed.")
            if event.button == 7:
                print("Button 'Start' was pressed.")

        if event.type == pygame.JOYHATMOTION:
            if my_joystick.get_hat(0) == (0, 1):
                keyboard = Controller()
                mouse.move(0, -10)
                print("DPad is Up")
            elif my_joystick.get_hat(0) == (0, -1):
                keyboard = Controller()
                mouse.move(0, 10)
                print("DPad is Down")
            elif my_joystick.get_hat(0) == (-1, 0):
                mouse.move(-10, 0)
                print("DPad is Left")
            elif my_joystick.get_hat(0) == (1, 0):
                mouse.move(10, 0)
                print("DPad is Right")
            elif my_joystick.get_hat(0) == (0, 0):
                keyboard = Controller()
                print("none")
Example #9
0
    if find_fist == ():
        find_hand = cascade_hand.detectMultiScale(frame_gray,
                                                  scaleFactor=1.05,
                                                  minNeighbors=10)

        if find_hand != ():
            mouse.click(pynput.mouse.Button.left, 1)

    if find_fist != () and find_fist_init != ():
        delx, dely, delw, delh = find_fist[0][0] - find_fist_init[0][
            0], find_fist[0][1] - find_fist_init[0][1], find_fist[0][
                2] - find_fist_init[0][2], find_fist[0][3] - find_fist_init[0][
                    3]

        mid_x = (delx + delx + delw) / 2
        mid_y = (dely + dely + delh) / 2
        mouse.move(-1 * 5 * delx, 5 * dely)
        # print (find_hand[0][0])

    find_fist_init = find_fist
    #To show the rectangle on the frame
    make_rect_contours(find_fist, frame, 255, 0, 0)
    make_rect_contours(find_hand, frame, 0, 0, 255)
    key = showFrame(frame)

    if (key == ord('x')):
        break

quit(vid)