示例#1
0
def main():
    print(time.time())
    print('Searching for window of CS...')
    hlcsWindowID = getWindowID()
    while hlcsWindowID == None:
        time.sleep(2)
        hlcsWindowID = getWindowID()
    print('Found CS at', hlcsWindowID)
    time.sleep(5)
    display = Display.Display()
    displayName = display.get_display_name()
    screen = display.screen()
    width = screen.width_in_pixels
    height = screen.height_in_pixels
    print('size1: {}x{}'.format(width, height))
    xCenter = int(width / 2)
    yCenter = int(height / 2)
    xdo = Xdo()
    while True:
        time.sleep(0.01)
        screenShot = ImageGrab.grab(xdisplay=displayName).load()

        if scanArea(screenShot, xCenter, yCenter, 10, 10):
            xdo.click_window(hlcsWindowID, 1)

        target = findTarget(screenShot, xCenter, yCenter, 350, 200)
        if target != None:
            xdo.move_mouse(xCenter + target[0], yCenter + target[1])
示例#2
0
def start_ns(url):

    # First, create the copy of the hard drive
    if DEBUG:
        print "creating the HD"

    # kill any previous binaries
    for proc in psutil.process_iter():
        if proc.name() == "previous":
            proc.kill()

    tar = tarfile.open(PRISTINE_HARD_DISK, 'r:gz')
    tar.extractall(ACTUAL_HARD_DISK_DIR)

    if DEBUG:
        print "done creating the HD"

    with pyvirtualdisplay.smartdisplay.SmartDisplay(visible=0,
                                                    size=(1300,
                                                          900)) as v_display:
        if DEBUG:
            print v_display
            print v_display.display

        with easyprocess.EasyProcess(PREVIOUS_BINARY) as previous:

            time.sleep(.50)
            xdo = Xdo()

            done = False
            while not done:
                wins = xdo.search_windows('Previous')
                # check if alive
                if not previous.is_alive():
                    print "Error, couldn't boot emulator"
                    return
                if wins:
                    done = True
                    window = wins[0]
                else:
                    time.sleep(.50)

            # Get the relative X and Y for the window
            loc = xdo.get_window_location(window)

            print "Booting up"

            # wait until we get to the login screen
            wait_until_login_screen(xdo, loc, window, v_display)

            print "Finally booted"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            log_into_ns(xdo, window)

            print "Waiting to log in"

            # wait for the screen to load
            wait_until_login_desktop(xdo, loc, window, v_display)

            print "Logged in"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Send the data
            send_url_to_ns(url)

            send_copy_command(xdo, window)

            time.sleep(.50)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            print "Starting the old dog"

            send_start_www_command(xdo, window)

            # Wait until WWW is ready
            wait_until_www_ready(xdo, loc, window, v_display)

            print "That old dog is ready"

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Close out the terminal
            # Command-q is the keyboard shortcut to quit
            xdo.send_keysequence_window(window, "Super_L+q")
            time.sleep(.50)
            select_open_document(xdo, loc, window)

            # Wait until Document Inspector is open
            print "Sending your input"
            wait_until_document_inspector_open(xdo, loc, window, v_display)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            move_to_address_field(xdo, loc, v_display)
            time.sleep(.50)
            xdo.click_window(window, 1)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            # Paste that shit!
            # Command-v is the keyboard shortcut
            xdo.send_keysequence_window(window, "Super_L+v")
            time.sleep(.50)

            current_image = v_display.waitgrab()
            send_screen_shot(current_image)

            print "That old dog can still visit URLs!"

            # if DEBUG:
            #     input("Wait for debugging")

            # Open it!
            xdo.send_keysequence_window(window, "Return")

            print "tbl would be proud"

            # Wait for 5 seconds, taking screenshots
            for i in xrange(5):
                time.sleep(1)
                current_image = v_display.waitgrab()
                send_screen_shot(current_image)

        # Crazy hack b/c something is sending an error message:
        # "XIO:  fatal IO error 0 (Success) on X server ":1001""
        # Which is freaking crazy, doesn't make any
        devnull = open(os.devnull, 'w')
        os.dup2(devnull.fileno(), 2)