return "" if args.version: print("{} v{}".format(progname, version)) exit() if not (filenames or filepat or xfilepat): argparser.print_help() exit() print("(!) select window to send keypress events ...") targetWin = xdo.select_window_with_click() if targetWin: winname = getWindowName(targetWin) print("selected window: {}".format(winname)) for changes in watch("."): winname = getWindowName(targetWin) if winpat and not re.match(winpat, winname): continue reload = any([included(e[1]) for e in changes]) time.sleep(args.delay) if reload: curWin = xdo.get_active_window() xdo.focus_window(targetWin) xdo.send_keysequence_window(targetWin, key.encode("utf-8")) xdo.focus_window(curWin) print("sending {} to {}".format(key, targetWin))
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)
from xdo import Xdo import ctypes if __name__ == '__main__': xdo = Xdo() current_window = ctypes.c_ulong(0) xdo.send_keysequence_window(current_window, b'F1')
if abs(70 - abs(approx[0][0][0] - approx[2][0][0])) < 10: ypos = abs(approx[1][0][1]) # TODO: Should adjust this based on the last position... # Current best settings: 880~895 if ypos > 885 and ypos < 895: # # 4K mode # xpos = abs(approx[0][0][0]) # D~10 F~80 J~160 K~240 key = 'UNKNOWN' if mode == '4K': # D F J K if abs(170 - xpos) < 5 and abs(dTime - currentTimeMillis()) > WAIT_TIME_MILLIS: key = 'D' xdo.send_keysequence_window(window_id, 'd'.encode('utf-8')) dTime = currentTimeMillis() elif abs(240 - xpos) < 5 and abs(fTime - currentTimeMillis()) > WAIT_TIME_MILLIS: key = 'F' xdo.send_keysequence_window(window_id, 'f'.encode('utf-8')) fTime = currentTimeMillis() elif abs(320 - xpos) < 5 and abs(jTime - currentTimeMillis()) > WAIT_TIME_MILLIS: key = 'J' xdo.send_keysequence_window(window_id, 'j'.encode('utf-8')) jTime = currentTimeMillis() elif abs(400 - xpos) < 5 and abs(kTime - currentTimeMillis()) > WAIT_TIME_MILLIS: key = 'K' xdo.send_keysequence_window(window_id, 'k'.encode('utf-8')) kTime = currentTimeMillis() elif mode == '7K': # S D F (space) J K L
from xdo import Xdo from time import sleep from loremipsum import get_sentences from random import randint xdo = Xdo() sleep(5) win_id = xdo.get_focused_window() while True: texts = get_sentences(randint(1,5)) speed = randint(50000, 1000000) for text in texts: xdo.enter_text_window(win_id, text, speed) xdo.send_keysequence_window(win_id, "Return")