示例#1
0
def exitWideProgram():
    mouse = mouseController()
    mouse.position = (1360, 8)
    time.sleep(2)

    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(2)
示例#2
0
def openFirefox(page):
    mouse = mouseController()
    keyboard = keyboardController()
    mouse.position = (10, 750)
    time.sleep(2)

    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(2)

    keyboard.type('Firefox')
    time.sleep(2)

    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
    time.sleep(2)

    with keyboard.pressed(Key.ctrl):
        time.sleep(2)
        keyboard.press('l')
    time.sleep(2)

    keyboard.type(page)
    time.sleep(2)

    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
    time.sleep(2)

    mouse.position = (10, 500)
    time.sleep(2)

    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(2)

    for i in range(60 * 20):
        keyboard.press(Key.page_down)
        time.sleep(1)

    with keyboard.pressed(Key.ctrl):
        keyboard.press('s')
    time.sleep(5)

    keyboard.type(page.split('/')[3] + '_' + page.split('/')[4] + '.html')
    time.sleep(5)
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
    time.sleep(2)
示例#3
0
def cursor_mover():
    start = t.time()
    mouse = mouseController()
    keyboard = Controller()

    while True:
        # Random movements
        movedirX = rand.randint(-100, 100)
        movedirY = rand.randint(-100, 100)

        mouse.move(movedirX, movedirY)
        keyboard.press(Key.space)

        # Every _ seconds
        t.sleep(2.0 - ((t.time() - start) % 2))
示例#4
0
def ACTIONS_DEFAULT(button):
    keyboard = keyboardController()
    mouse = mouseController()

    if button == 'A7':
        # keyboard.type('hoi')
        keyboard.press(Key.alt)
        keyboard.press(Key.tab)
        keyboard.release(Key.alt)
        keyboard.release(Key.tab)
        printAction(button + "/default: alt tab")

    elif button == 'B0':
        keyboard.press(Key.ctrl)
        keyboard.press('w')
        keyboard.release(Key.ctrl)
        keyboard.release('w')
        printAction(button + "/default: Closing tab")
示例#5
0
from pynput.mouse import Button, Controller as mouseController
from pynput.keyboard import Key, Controller as keyController
import time
import pyautogui
import random
import cv2
import numpy as np
from PIL import Image

for u in range(1):
    mouse = mouseController()
    keyboard = keyController()

    num3 = random.randint(3600, 6000)
    #num3 = 1
    timespent = num3 / 60
    print("wait time =", timespent)

    timespent = 0

    print("wait time =", timespent)

    time.sleep(timespent)

    mouse.position = (117, 1057)
    mouse.click(Button.left, 1)

    time.sleep(2)

    for char in "chrome":
        keyboard.press(char)
示例#6
0
def main():

    global args
    imgPath = args.image
    preClickDelay = args.delay
    searchPeriod = 1 / args.frequency
    postClickDelayMin = args.postClickDelayMin
    postClickDelayMax = args.postClickDelayMax
    coordinateFactor = args.coordinateFactor

    if not Path(imgPath).exists():
        print("\nPath supplied does not exist.\n")
        parser.print_help()
        exit(1)

    if postClickDelayMax < 0 or postClickDelayMin < 0 or preClickDelay < 0:
        print("\nDelays must be non-negative.\n")
        parser.print_help()
        exit(1)

    # boolean for mouse use status
    interfaceInUse = False

    # handle mouse events
    def in_use(*args):
        nonlocal interfaceInUse
        interfaceInUse = True

    # keyboard and mouse controllers
    keyboard = keyboardController()
    mouse = mouseController()

    # listen to mouse
    mouseListener = _mouseListener(on_move=in_use,
                                   on_click=in_use,
                                   on_scroll=in_use)
    mouseListener.start()

    # listen to keyboard
    keyboardListener = _keyboardListener(on_press=in_use, on_release=in_use)
    keyboardListener.start()

    # track how many clicks have been done
    counter = 0

    print('Active and searching...')
    while True:
        try:
            interfaceInUse = False
            # check for image at approximately 3Hz
            sleep(searchPeriod)

            # search for the image
            try:
                location = pg.locateCenterOnScreen(imgPath, confidence=0.9)
            #stuff is buggy...
            except TypeError:
                continue
            except IndexError:
                continue

            # if it's not found, continue
            if location is None:
                continue

            # delay between seeing image and clicking it
            if preClickDelay != 0:
                print(
                    f'Image found, {preClickDelay} seconds to touch an interface and abort.'
                )
            sleep(preClickDelay)

            if not interfaceInUse:
                # get original mouse position
                origPos = mouse.position

                # get the correct click location, suspect
                # this need is related to the resolution on this mac
                x = location.x / coordinateFactor
                y = location.y / coordinateFactor

                # click the image twice, once to activate the window
                # another time to actually click the button if it is one
                pg.click(x, y)
                pg.click(x, y)

                # put mouse back to original location
                mouse.position = origPos

                # switch back to the previously active window
                with keyboard.pressed(Key.cmd):
                    keyboard.press(Key.tab)
                    sleep(0.18)
                    keyboard.release(Key.tab)

                # update counter and inform user what has occured
                counter += 1
                print(f'Clicked it {counter} times.')

                # sleep for a random amount of time between 5 and 10 sec
                sleepTime = uniform(postClickDelayMin, postClickDelayMax)
                print(f'Sleeping for {sleepTime} seconds.')
                sleep(sleepTime)
                print('Active and searching...')

            else:
                print('Click aborted.')

        # ^C to pause, then again to quit, or any key to resume
        except KeyboardInterrupt:
            try:
                input('\nPaused, press any key to continue, or ^C to quit.')
            except KeyboardInterrupt:
                break

    # stop listening to mouse and keyboard
    mouseListener.stop()
    keyboardListener.stop()

    # clear console
    with keyboard.pressed(Key.ctrl):
        keyboard.press('l')
        keyboard.release('l')
示例#7
0
 def __init__(self):
     self.mouse = mouseController()
     self.keyboard = kbController()