Exemplo n.º 1
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)
Exemplo n.º 2
0
def ACTIONS_CHROME(button):
    keyboard = keyboardController()

    if button == 'A7':
        keyboard.press(Key.alt)
        keyboard.press(Key.tab)
        keyboard.release(Key.alt)
        keyboard.release(Key.tab)
        printAction(button + "/CHROME: alt tab")

    elif button == 'B0':
        keyboard.press(Key.ctrl)
        keyboard.press('w')
        keyboard.release(Key.ctrl)
        keyboard.release('w')
        printAction(button + "/CHROME: Closing tab")
Exemplo n.º 3
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")
Exemplo n.º 4
0
from pynput.keyboard import Key, Controller as keyboardController
from pynput.mouse import Button, Controller as mouseController
import time

#set ups mouse and keyboard
m = mouseController()
k = keyboardController()

#opens windows and searches for idle
k.press(Key.cmd)
k.release(Key.cmd)
time.sleep(.3)
k.type("idle")
time.sleep(.2)
k.press(Key.enter)
k.release(Key.enter)
time.sleep(2)

#opens a new file
k.press(Key.ctrl)
k.press("n")
k.release(Key.ctrl)
k.release("n")
time.sleep(.5)

#imports modules to run shit
k.type("from pynput.keyboard import Key, Controller as keyboardController")
k.press(Key.enter)
k.release(Key.enter)
time.sleep(.5)
k.type("import time")
Exemplo n.º 5
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')