def on_End_analog(): logging.info(30*'_' + " on_End_analog") k = PyKeyboard() #抬起功能按键Ctrl,否则End效果会变为Ctrl+End效果 k.release_key(k.control_key) k.tap_key(k.end_key) return False
class Keyboard(object): def __init__(self): super(Keyboard, self).__init__() self.k = PyKeyboard() def write(self,text): self.k.type_string(text)
class HIDremServerProtocol(com.LengthPrefixedReceiver): """The communication protocol.""" def setup(self): self.k = PyKeyboard() self.m = PyMouse() def got_message(self, msg): """called when a message was received.""" if not msg: return idb, msg = msg[0], msg[1:] if idb == common.ID_PING: # echo message self.send_message(idb + msg) elif idb == common.ID_KEYBOARD: action, keyname = msg[0], msg[1:] if action == common.ACTION_PRESS: self.k.press_key(keyname) elif action == common.ACTION_RELEASE: self.k.release_key(keyname) else: # protocol violation self.close() elif idb == common.ID_MOUSE: pass else: # protocol violation self.close()
class Robot(object): def __init__(self): self.mouse = PyMouse() self.keyboard = PyKeyboard() self.przyciskPSP2klawiatura = {'up': 'w', 'right': 'd', 'down': 's', 'left': 'a', 'triangle': self.keyboard.enter_key, 'circle': 'f', 'cross': 'g', 'square': 'h', 'l': self.keyboard.control_r_key, 'r': self.keyboard.shift_r_key, 'start': 'k', 'select': 'l'} def reaguj(self, x, y, przyciskPSP2Stan): self.reaguj_mysz(x, y) self.reaguj_klawiatura(przyciskPSP2Stan) def reaguj_mysz(self, x, y): max_predkosc_kursora = 0.00000000000000000000000000000000000000000000000000001 x += int((x / float(128)) * max_predkosc_kursora + self.mouse.position()[0]) y += int((y / float(128)) * max_predkosc_kursora + self.mouse.position()[1]) x, y = min(self.mouse.screen_size()[0], x), min( self.mouse.screen_size()[1], y) x, y = max(0, x), max(0, y) self.mouse.move(x, y) def reaguj_klawiatura(self, przyciskPSP2Stan): for przycisk_psp, czyWcisniety in przyciskPSP2Stan.iteritems(): przycisk_klawiaturowy = self.przyciskPSP2klawiatura[przycisk_psp] if czyWcisniety == '1': if przycisk_klawiaturowy == 'g': self.mouse.click(*self.mouse.position()) break self.keyboard.press_key(przycisk_klawiaturowy) else: self.keyboard.release_key(przycisk_klawiaturowy)
def combo(*arg): theCombo = arg[:-1] theVelocity = arg[-1] # not used k = PyKeyboard() k.press_keys(theCombo)
def typeString(s): #m = PyMouse() k = PyKeyboard() #print args #k.press_keys(args) k.type_string(s)
def switch_to_highlayer(outName, frameNumber, segNumber): #totalIdx = len(inputList) ''' timeInterval defines the print frequency of the frame number in the terminal. ''' timeInterval = 0.4 frameStep = timeInterval*25 k = PyKeyboard() logName = outName + ".log" tmpIdx = 1 while True: text = subprocess.check_output(["tail", "-1", logName]) #tmpIdx = totalIdx - len(inputList)+1 if "PAUSE" in text and "===== PAUSE =====\rV:" not in text: sleep(timeInterval) continue elif "Exiting" in text: break else: print text sleep(timeInterval) frameIdx = parse_frame_idx(text) if frameIdx >= frameNumber*tmpIdx and frameIdx < frameNumber*tmpIdx + frameStep: print "======================================" print "currentFrame is: "+str(frameIdx)+".\n" if bool(stepList): tmpIdx = tmpIdx +1 value = stepList.pop(0) if value >0: for t in range(value): k.tap_key('b') print "switch to higher layer" sleep(0.1) else: break
def on_End_combo(): logging.info(30*'_' + " on_End_combo") k = PyKeyboard() #抬起功能按键Ctrl,否则End效果会变为Ctrl+End效果 k.release_key(k.control_key) k.press_keys([k.end_key, ';', k.enter_key]) return False
def faceTracker(): print "Face Track running" k = PyKeyboard() faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') video_capture = cv2.VideoCapture(0) centerX = 0; while True: # Capture frame-by-frame ret, frame = video_capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = faceCascade.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=5,minSize=(150, 150), ) #Draw a rectangle around the face if len(faces) >= 1: (x,y,w,h) = faces[0] cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) centerNew = x + w/2 if centerNew > centerX + 10: print('left') k.tap_key('Left') if centerNew < centerX - 10: print('right') k.tap_key('Right') centerX = centerNew if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything is done, release the capture video_capture.release() cv2.destroyAllWindows()
def xdomenu(): """interacts with a simple menu.""" char_to_bin = {'s': 'srmenu', 'j': 'jmenu', 'c': 'clipmenu', 't': 'terminal', 'u': 'urxvt', 'p': 'pomodoro', ' ': 'moveempty'} keybrd = PyKeyboard() k_menu = keybrd.menu_key persistent = False print_menu(persistent) while True: sleep(0.1) stdout.flush() char = getchar() try: cmd = char_to_bin[char] print_flush(cmd) if persistent: sleep(0.2) keybrd.tap_key(k_menu) except KeyError: if char == '\t': persistent = not persistent print_menu(persistent) else: keybrd.tap_key(k_menu)
class KLKeyboard(object): def __init__(self): self.keyboard = PyKeyboard() pass def hitKey(self, key): self.keyboard.tap_key(key)
def type_msg(string): """ Stimulates typing a string of characters Args: string (str) : A string of characters to enter """ k = PyKeyboard() k.type_string(string)
def run(self): # Set up the keyboard sim K = PyKeyboard() # Let the program start running # Run till it's over. if self.lines: for i in lines: K.type_string(str(i))
def callSequence(*args): m = PyMouse() k = PyKeyboard() print args #k.press_keys(args) #k.type_string(args[0]) keys = ["cmd", "a"] #callArray(keys) k.press_keys(keys)
def keypress(key): """ Simulates a key press Args: key (str) : the key [a-zA-Z0-9] to enter. Use 'enter' for the return key """ k = PyKeyboard() if key == 'enter': key = k.return_key k.tap_key(key)
def new_tab(): print('*_* new_tab') k = PyKeyboard() k.release_key(k.control_l_key) k.press_key(k.control_l_key) k.tap_key('t') k.release_key(k.control_l_key)
def close_tab(): print('*_* new_tab') k = PyKeyboard() k.release_key(k.control_l_key) k.press_key(k.control_l_key) k.tap_key(k.function_keys[4])F k.release_key(k.control_l_key)
def run(self, some_input=[]): # print("Run") # How long to run for counter = 0 # Remove "run" from the input some_input.pop(0) # Get the run number for i in some_input: if i == "cmd": command(some_input) elif i: try: counter = int(i) except ValueError: print("Value Error in Run") pass finally: some_input.remove(i) # If the counter didn't get defined. if counter == 0: counter = len(self.list_of_runs) # NOW we can run. We should check the length of the # command sequences, and the number of runs i = 0 # times through string = "" # string that will be printed length = len(self.list_of_runs) # Allow for 5 seconds to change windows print("Please Change Windows Now.") sleep(5) some_keyboard = PyKeyboard() # DO WORK YO while i < counter and i < length: string = self.list_of_runs.pop(0) sys.stdout.write(string) some_keyboard.type_string(string) sleep(self.sleep_num) i += 1 # Reset the variable if empty. if not self.list_of_runs: self.list_of_runs.append("")
def keyboard(event): if event.KeyID == 27: key = PyKeyboard() print "key1" key.press_key(162) # ctrl key.press_key(67) # c key.release_key(67) # c key.release_key(162) # ctrl print "key2" print event.KeyID return True
def fill_board(start_board, solution_board, x,y,width,height): cell_width = width / 9 cell_height = height / 9 mouse = PyMouse() keyboard = PyKeyboard() for i in range(0,9): for j in range(0,9): # insert only empty cell if start_board.values[j][i] == 0: sleep(0.1) mouse.click(x + cell_width*(j+0.5), y+cell_height*(i+0.5)) sleep(0.01) keyboard.tap_key(str(solution_board.values[j][i]))
def process_message(in_msg, midi_to_shortcut): """ processes message """ keyboard = PyKeyboard() print(in_msg) try: if (in_msg.note, in_msg.channel) in midi_to_shortcut and in_msg.type != 'note_off': shortcut = midi_to_shortcut[(in_msg.note, in_msg.channel)] print('shortcut: ', shortcut) for key in shortcut: keyboard.press_key(key) for key in shortcut: keyboard.release_key(key) except OSError: print('note not recognized')
def key_pressed(action): print('*_* key_pressed %s' % action) k = PyKeyboard() if action == 'enterKey': k.tap_key(k.enterkey) elif action == 'backSpace': k.tap_key(k.backspace_key) elif action == 'spaceKey': k.tap_key(k.space_key) else: k.tap_key('%s' % action)
def main(): #Get an instance of PyKeyboard, and our custom PyMouseEvent keyboard = PyKeyboard() mouse = AbortMouse() input('Press Enter when ready.') print('Typing will begin in {0} seconds...'.format(opts['--pause'])) time.sleep(opts['--pause']) mouse.start() with open(opts['<file>'], 'r') as readfile: for line in readfile: if not mouse.state: print('Typing aborted!') break keyboard.type_string(line, opts['--interval'])
def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, 'EYE Typing Keypad', pos=(0, 0), size=wx.DisplaySize()) self.panel = wx.Panel(self) self.keyboard_control = PyKeyboard() #place to store what is being entered font1 = wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.BOLD) self.text = wx.TextCtrl(self.panel, 30, "", size=wx.DLG_SZE(self, 500, 40)) self.text.SetFont(font1) self.outer_box = wx.BoxSizer(wx.VERTICAL) self.outer_box.Add(self.text, border=5, flag=wx.ALL) #place to make the actual keyboard self.keyboard = wx.BoxSizer(wx.VERTICAL) self.keys = [chr(ord('a') + i) for i in range(10)] self.keys.append('space') # chr(ord('a')) + i self.keys = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'space', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'] i = 1 self.hash = {} self.hash_label = {} self.key_buttons = [] for key in self.keys: b = wx.Button(self.panel, i, key, size=wx.DLG_SZE(self, 50, 50)) self.key_buttons.append(b) self.Bind(wx.EVT_BUTTON, self.connect_keys, b) self.hash_label[i] = key self.hash[i] = b if key == "space": self.hash_label[i] = 'spc' i += 1 i = 0 j = 0 self.keybox = [] font = wx.Font(20, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.BOLD) k = 1 self.flag = [False] * 28 for button in self.key_buttons: if i % 7 == 0: if self.keybox != []: self.keyboard.AddSpacer(40) self.keyboard.Add(self.keybox[j]) j += 1 self.keybox.append(wx.BoxSizer(wx.HORIZONTAL)) button.Bind(wx.EVT_ENTER_WINDOW, self.change_colour) button.Bind(wx.EVT_LEAVE_WINDOW, self.revert_colour) button.SetFont(font) self.keybox[j].Add(button) self.keybox[j].AddSpacer(40) i += 1 k += 1 self.keyboard.AddSpacer(40) self.keyboard.Add(self.keybox[j]) self.outer_box.Add(self.keyboard, border=5, flag=wx.ALL) self.panel.SetSizer(self.outer_box)
class ScreenSaverPreventer(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.key = PyKeyboard() def doSomething(self): self.key.press_key(self.key.control_l_key) self.key.release_key(self.key.control_l_key) def run(self): self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.doSomething) self.timer.start(59000) # 59 sec def stop(self): self.timer.stop()
def __init__(self): # Prepare to take control over user keyboard self.keyboard = PyKeyboard() # Prepare for getting pixel colors from the screen self.gdk_root_window = gtk.gdk.get_default_root_window() self.gdk_screen_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 1, 1) # Prepare color recognition prepare_colors_dict()
def __init__(self, stop_event): self.exceptions = (StoppedException, requests.exceptions.ConnectionError, socket.error, websocket.WebSocketBadStatusException, websocket.WebSocketConnectionClosedException) self.stop_event = stop_event self.browser = None self.tab = None self.k = PyKeyboard() self.m = PyMouse()
def key_combo(key0, key1): k = PyKeyboard() if key0 == 'ctrl': key0 = k.control_key k.press_key(key0) k.tap_key(key1) k.release_key(key0)
def previous_focus(): print('*_* next_focus') k = PyKeyboard() k.press_key(k.shift_key) k.tap_key(k.tab_key) k.release_key(k.shift_key)
def change_window_start(): print('*_* change_window_start') k = PyKeyboard() k.release_key(k.alt_key) k.press_key(k.alt_key) k.tap_key(k.tab_key)
def pLabel(pep, spec, gene, row_no): m = PyMouse() k = PyKeyboard() # ALL button m.click(1243, 204) sleep(2) m.click(362, 762) sleep(1) m.click(362, 762) sleep(0.3) m.click(362, 762) sleep(1) for n in range(30): k.press_key(k.backspace_key) sleep(1) k.type_string(spec) sleep(1) k.press_key(k.enter_key) sleep(1) capture(pep, spec, gene, row_no, 0) sleep(1) m.click(609, 182) sleep(1) # peptide m.click(132, 728) sleep(1) m.click(132, 728) sleep(0.3) m.click(132, 728) sleep(1) k.press_key(k.backspace_key) sleep(1) k.type_string(pep) sleep(1) k.press_key(k.enter_key) sleep(1) capture(pep, spec, gene, row_no, 1) sleep(1)
import tensorflow as tf import thinkdsp import thinkplot import thinkstats2 import matplotlib.pylab as plt import pandas as pd import time from IPython import display import os import pymouse, pykeyboard, os, sys from pymouse import * from pykeyboard import PyKeyboard import time m = PyMouse() k = PyKeyboard() beta = 0.35 i = 1 frt = 1500 left_seg = 200 right_seg = 400 def unbias(ys): """Shifts a wave array so it has mean 0. ys: wave array returns: wave array """
def __init__(self): self.k = PyKeyboard()
def main(): def s_open(s_s): old_msg = '' try: s_s.close() except: pass while True: try: s_s.open() except Exception: msg = traceback.format_exc() if msg != old_msg: print(msg) sys.stdout.flush() old_msg = msg time.sleep(2) else: serial_conn.flushOutput() serial_conn.flushInput() break print(s_s) sys.stdout.flush() return s_s try: k = PyKeyboard() except: traceback.print_exc() return port, rate = parse_c_line() try: serial_conn = serial.Serial() except serial.SerialException: traceback.print_exc() return serial_conn.port = port if rate: serial_conn.baudrate = rate serial_conn.timeout = 0.2 serial_conn = s_open(serial_conn) while True: try: #s = sys.stdin.readline().strip() s = serial_conn.readline().strip() if not s: continue k.type_string(s.decode('utf8')) k.tap_key(k.enter_key) except serial.SerialException: serial_conn = s_open(serial_conn) except KeyboardInterrupt: break except Exception as Err: print('*' * 20) sys.stdout.flush() traceback.print_exc() #serial_conn.flushOutput() #serial_conn.flushInput() try: serial_conn.close() except: pass
def main(): parser = argparse.ArgumentParser(version=__version__) parser.add_argument('--new', action='store_true', default=False, dest='new_token', help='Generate a new Soft Token') parser.add_argument('--delete', action='store_true', default=False, dest='delete_token', help='Delete a Soft Token') parser.add_argument('--list', action='store_true', default=False, dest='list_tokens', help='List configured tokens') parser.add_argument('--token', '-t', required=False, dest='token_name', help='Soft Token name') parser.add_argument('--hash', default='sha256', dest='hash_function', choices=('sha1', 'sha256', 'sha512'), help='Hash ' 'function to use (default is sha256)') parser.add_argument('--digits', '-d', type=int, default=6, dest='digits', help='OTP Length (default is 6)') parser.add_argument('--length', '-l', type=int, default=20, dest='seed_length', help='Seed length in bytes ' '(default is 20)') parser.add_argument('-X', action='store_true', default=False, dest='print_focus', help='Output the OTP where ' 'the current focus is') parser.add_argument('-C', action='store_true', default=False, dest='copy_clipboard', help='Copy OTP to clipboard') args = parser.parse_args() if args.list_tokens: print_tokens() sys.exit(0) if args.token_name is None: print("A Token name is required for this action") parser.print_help() sys.exit(-1) if args.new_token: create_token(args.token_name, args.hash_function, args.digits, args.seed_length) sys.exit(0) if args.delete_token: delete_token(args.token_name) sys.exit(0) if args.list_tokens: print_tokens() sys.exit(0) # Generate new OTP if the token exists cfg = load_config() if not cfg.has_section(args.token_name): print('Token %s does not exist' % args.token_name) sys.exit(2) if args.hash_function == 'sha1': hf = hashlib.sha1 elif args.hash_function == 'sha256': hf = hashlib.sha256 elif args.hash_function == 'sha512': hf = hashlib.sha512 seed = cfg.get(args.token_name, 'seed') totp = pyotp.TOTP(seed, digest=hf, digits=args.digits) otp = totp.now() if args.print_focus: from pykeyboard import PyKeyboard k = PyKeyboard() k.type_string(otp) elif args.copy_clipboard: pyperclip.copy(otp.encode('ascii')) else: print(otp)
print('fault', end=' ') faultcount += 1 #print(pred) # result.append(pred) if is_showimg: print(peopleatt[peopleattlabel.index('1')]) print(personatt(score1[0])) res = label2name(pred) res = '\n'.join(res) ttfont = ImageFont.truetype(font='pixel.ttf', size=(img_arr.shape[1] // 20)) draw = ImageDraw.Draw(img_show) draw.text((0.1 * img_show.size[0], 0.1 * img_show.size[1]), res, fill=(0, 255, 0), font=ttfont) img_show.show() a = easygui.buttonbox(msg='next image', choices=('Y')) if a != 'Y': break # time.sleep(5) k = PyKeyboard() k.tap_key(k.escape_key) img_show.close() print('-' * 30) print('right count:', rightcount) print('fault count:', faultcount)
from pymouse import PyMouse from pykeyboard import PyKeyboard k = PyKeyboard() s = "sssss" for i in s: k.tap_key(i) # 光标在哪就在哪输入 # k.tab_key(k.enter_key)
def upload_file(self, filename): pk = PyKeyboard() # pk.tap_key(pk.shift_key) 切换中英文 pk.type_string(filename) # 输入文件路径 time.sleep(2) pk.tap_key('return')
from selenium import webdriver from pymouse import * from pykeyboard import PyKeyboard import time driver = webdriver.Chrome() driver.get("https://www.autoitscript.com/files/autoit3/autoit-v3-setup.exe") m = PyMouse() k = PyKeyboard() time.sleep(3) # 默认在取消按钮上,先切换到保存文件上 k.release_key(k.tab_key) # 发送TAB键 time.sleep(3) # 第一次回车没生效,所以多发一次回车 k.press_key("ENTER") # 发送回车键 k.press_key("ENTER") # 发送回车键
# from pymouse import PyMouse import Quartz from pykeyboard import PyKeyboard from time import sleep #initialize the keyboard simulator keyboard = PyKeyboard() #presses the key keyboard.press_key('x') #waits five seconds before releasing the key sleep(5) #releases the key keyboard.release_key('x')
class GameWindow: def __init__(self, suspendCallback): self.suspendCallback = suspendCallback self.winy = 0 self.winx = 0 self.mouse = PyMouse() self.keyboard = PyKeyboard() self.cvmethod = cv2.TM_CCOEFF_NORMED self.startpointer = cv2.imread('img/start.png') self.progimg = cv2.imread('img/prog.png') self.logger = logging.getLogger('herobot.gamewindow') self.getwindow() self.herosScrollUpLocation = (549, 190) self.herosScrollDownLocation = (549, 623) def getwindow(self): im = ImageGrab.grab().convert('RGB') big = np.array(im) big = big[:, :, ::-1].copy() r = cv2.matchTemplate(self.startpointer, big, self.cvmethod) y, x = np.unravel_index(r.argmax(), r.shape) self.winx = x - 14 self.winy = y - 92 self.logger.info('Window found at {}; {}'.format( str(self.winx), str(self.winy))) # self.hwinx = self.winx + 11 # self.hwiny = self.winy + 171 # @timing def grab_ocr(self, x, y, w, h): x = self.winx + x y = self.winy + y im = ImageGrab.grab(bbox=(x, y, x + w, y + h)).convert('RGB') # debug output # imcolor = cv2.cvtColor(np.array(im), cv2.COLOR_RGB2BGR) # cv2.imwrite('tests/grab_ocr.bmp', imcolor) pix = im.load() for x in range(im.size[0]): for y in range(im.size[1]): if pix[x, y] != (254, 254, 254): pix[x, y] = 0 return pytesseract.image_to_string(im, lang='eng') def grab_screen(self, x, y, w, h): """ Take screenshot of the specified region of gamewindow Save a bmp into disk for debuging perpose. I wasn't able to copile cv2 with GTK support. Hint, you can open this .bmp in Sublime Text it will refresh automatically when file change. """ im = ImageGrab.grab(bbox=(x, y, x + w, y + h)) big = np.array(im) # Debug output # logger.debug('big shape: {}'.format(big.shape)) cv2.imwrite('tests/big.bmp', cv2.cvtColor(big, cv2.COLOR_RGB2BGR)) big = big[:, :, ::-1].copy( ) # <- IndexError: too many indices for array return big def grab_screenlastvisiblehero(self): """ capture heroes window lower region where last available hero will be """ leftmargin = 160 topmargin = 383 return self.grab_screen(self.winx + leftmargin, self.winy + topmargin, 272, 210) def grab_screen_visible_hero(self): """ capture heroes window from top to almost bottom """ leftmargin = 160 topmargin = 175 return self.grab_screen(self.winx + leftmargin, self.winy + topmargin, 272, 350) def click(self, location, times): x, y = location for i in range(times): self.mouse.click(self.winx + x, self.winy + y) sleep(0.02) def scroll_top(self): self.click(self.herosScrollUpLocation, pageScrollClicks * scrollPages) sleep(0.4) def scroll_bottom(self): self.click(self.herosScrollDownLocation, pageScrollClicks * scrollPages) sleep(0.4) def scroll_page_up(self): self.click(self.herosScrollUpLocation, pageScrollClicks) sleep(0.4) def scroll_page_down(self): self.click(self.herosScrollDownLocation, pageScrollClicks) sleep(0.4) # @timing def find_img_location(self, small, x, y, w, h): im = ImageGrab.grab(bbox=(x, y, x + w, y + h)) big = np.array(im) # Debug output # self.logger.debug('big shape: {}'.format(big.shape)) cv2.imwrite('tests/big.bmp', cv2.cvtColor(big, cv2.COLOR_RGB2BGR)) big = big[:, :, ::-1].copy( ) # <- IndexError: too many indices for array while True: try: r = cv2.matchTemplate(small, big, self.cvmethod) break except: self.log.error("Warning: failed to grab image") continue y, x = np.unravel_index(r.argmax(), r.shape) loc = np.where(r >= 0.95) if loc.count(x) > 0 and loc.count(y) > 0: return (x, y) else: return (None, None) def find_img_location(self, small): leftmargin = 160 topmargin = 383 (x, y) = self.find_img_location(small, self.winx + leftmargin, self.winy + topmargin, 272, 210) if x is not None: return (x + leftmargin, y + topmargin) return (None, None) def findvisibleheroname(self, hero): x, y = self.find_img_location(hero.img) if x is None: x, y = self.find_img_location(hero.goldimg) return (x, y) def find_hero_name(self, hero, scrolldownfirst=False): x, y = self.findvisibleheroname(hero) if x is not None: return (x, y) if not scrolldownfirst: self.scroll_top() for i in range(scrollPages): x, y = self.findvisibleheroname(hero) if x is not None: return (x, y) break self.scroll_page_down() # make another pass from the top... if scrolldownfirst: self.scroll_top() for i in range(scrollPages): x, y = self.findvisibleheroname(hero) if x is not None: return (x, y) break self.scroll_page_down() return (None, None) def find_herolevel(self, y): raw = self.grab_ocr(312, y + 20, 121, 25) self.logger.debug('find_herolevel read: "{}"'.format(raw)) num = ''.join(ch for ch in raw if ch.isdigit()) try: return int(num) except: return 0 def findvisiblehero(self, herorange: int): # x, y = self.findvisibleheroname(hero) # result = self.findvisibleheroworker(herorange) # if result: # x, y = result # return VisibleHero(x, y) big = self.grab_screenlastvisiblehero() try: hero, x, y = self.findvisibleheroworker(herorange, big) except TypeError: return (None, VisibleHero(None, None)) else: if x is not None and y is not None: return (hero, VisibleHero(x, y)) else: return (None, VisibleHero(None, None)) def callback(self, result): if result: self.logger.info('Hero found, stop other process') self.pool.terminate() def findvisibleheroworker(self, herorange: int): pool = Pool() for i in reversed(range(herorange)): result = pool.apply_async(self.findvisibleheroname, args=self.heroes[i], callback=self.callback) self.logger.info('Searching for hero number {}'.format(i)) pool.close() pool.join() return result.get(timeout=10) def find_hero(self, hero, scrolldownfirst=False): self.logger.info('searching for %s ...' % hero.name) x, y = self.find_hero_name(hero, scrolldownfirst) self.logger.debug('Found {} at {}; {}'.format(hero.name, str(x), str(y))) if x is not None: return (VisibleHero(x, y), self.find_herolevel(y)) else: return (None, None) def level_up_100(self, visibleHero): x, y = visibleHero.hire_location() self.keyboard.press_key(self.keyboard.control_key) self.slow_click(x, y) self.logger.debug(f'level_up_100: clicking at {x} px, {y} px') self.keyboard.release_key(self.keyboard.control_key) def upgrade(self, visibleHero, index): x, y = visibleHero.upgrade_location(index) self.slow_click(x, y) def check_prog(self): x, y = self.find_img_location(self.progimg, self.winx + 1090, self.winy + 227, 46, 55) if x is None and y is None: self.logger.debug( 'check_prog not seen OFF auto-progress indicator. Do nothing.') return else: self.logger.debug( 'check_prog clicked to activate auto-progression') self.slow_click(self.winx + 1115, self.winy + 252) def ascend_confirm(self): self.slow_click(self.winx + 490, self.winy + 420) def slow_click(self, x, y): sleep(0.15) self.mouse.click(x, y) sleep(0.15) def click_monster(self, times): self.logger.info('clicking monster ...') for i in range(times): sleep(0.025) self.mouse.click(self.winx + 700, self.winy + 250) self.suspendCallback() def use_skills(self): self.keyboard.tap_key('1') self.keyboard.tap_key('2') self.keyboard.tap_key('8') self.keyboard.tap_key('3') self.keyboard.tap_key('9') self.keyboard.tap_key('4') self.keyboard.tap_key('5') self.keyboard.tap_key('6') self.keyboard.tap_key('7') def grabsave(self) -> dict: self.slow_click(self.winx + 1116, self.winy + 26) # Click on wrench self.slow_click(self.winx + 278, self.winy + 78) # Click on Save sleep(0.2) self.keyboard.press_key(self.keyboard.escape_key) sleep(0.2) self.slow_click(self.winx + 945, self.winy + 29) # Click on close sleep(0.2) self.slow_click( self.winx + 945, self.winy + 29) # Click on close again in case windows wasn't active return extract_save_from_clipboard()
# the interested but usually not programming user when she or he does not need # to jump to different places or even files while trying to understand what's # going on here. from pymouse import PyMouse from pykeyboard import PyKeyboard from time import sleep, time # Instantiate a mouse and a keyboard. # A PyMouse() and a PyKeyboard() have certain methods that allow # easy access to typical features of such peripherals like moving the # pointer to a certain position or pressing keyboard buttons. mouse = PyMouse() keyboard = PyKeyboard() # Just reminding the user of sth. very important. print '''\n\n ATTENTION: DON'T MOVE THE WINDOW OF THE OBR-PROGRAM, AFTER THE POSITION OF THE <FILE> BUTTON WAS DETERMINED! See the instructions that accompany this program, how to use it.\n ''' # Don't do more analyses than the number stated here. # # Users tend to make mistakes. E.g. pressing too fast ENTER before
def compare(self, com, args, testing): """Method to dragonfire's command structures of keyboard keys ability. Args: com (str): User's command. args: Command-line arguments. """ self.testing = testing doc = nlp(com) h = Helper(doc) if (h.check_nth_lemma(0, "keyboard") or h.check_nth_lemma(0, "type")) and not args["server"]: n = len(doc[0].text) + 1 with nostdout(): with nostderr(): k = PyKeyboard() if not self.testing: for character in com[n:]: k.tap_key(character) k.tap_key(" ") return "keyboard" if (h.directly_equal(["enter"]) or (h.check_adj_lemma("new") and h.check_noun_lemma("line"))) and not args["server"]: with nostdout(): with nostderr(): k = PyKeyboard() if not self.testing: k.tap_key(k.enter_key) return "enter" if h.check_adj_lemma("new") and h.check_noun_lemma( "tab") and not args["server"]: with nostdout(): with nostderr(): k = PyKeyboard() if not self.testing: k.press_keys([k.control_l_key, 't']) return "new tab" if h.check_verb_lemma("switch") and h.check_noun_lemma( "tab") and not args["server"]: with nostdout(): with nostderr(): k = PyKeyboard() if not self.testing: k.press_keys([k.control_l_key, k.tab_key]) return "switch tab" if h.directly_equal(["CLOSE", "ESCAPE"]) and not args["server"]: with nostdout(): with nostderr(): k = PyKeyboard() if not self.testing: k.press_keys([k.control_l_key, 'w']) k.tap_key(k.escape_key) return "close" if h.check_lemma("back") and h.max_word_count( 4) and not args["server"]: with nostdout(): with nostderr(): k = PyKeyboard() if not self.testing: k.press_keys([k.alt_l_key, k.left_key]) return "back" if h.check_lemma("forward") and h.max_word_count( 4) and not args["server"]: with nostdout(): with nostderr(): k = PyKeyboard() if not self.testing: k.press_keys([k.alt_l_key, k.right_key]) return "forward" if (h.check_text("swipe") or h.check_text("scroll")) and not args["server"]: if h.check_text("left"): with nostdout(): with nostderr(): m = PyMouse() if not self.testing: m.scroll(0, -5) return "swipe left" if h.check_text("right"): with nostdout(): with nostderr(): m = PyMouse() if not self.testing: m.scroll(0, 5) return "swipe right" if h.check_text("up"): with nostdout(): with nostderr(): m = PyMouse() if not self.testing: m.scroll(5, 0) return "swipe up" if h.check_text("down"): with nostdout(): with nostderr(): m = PyMouse() if not self.testing: m.scroll(-5, 0) return "swipe down" if h.directly_equal(["PLAY", "PAUSE", "SPACEBAR" ]) and not args["server"]: with nostdout(): with nostderr(): k = PyKeyboard() if not self.testing: k.tap_key(" ") return "play" return None
def send_key(key): '''simulates key press''' keyboard = PyKeyboard() keyboard.press_key(key) keyboard.release_key(key)
image_save = [] for i in os.listdir(r"./yzm"): now_image = Image.open(r"./yzm/" + i) # now_image.show() for j in range(4): child_image = now_image.crop((6 + 15 * j, 1, 6 + 15 * (j + 1), 28)) image_save.append(child_image) new_vector.append(Identification.identify(child_image)) yanzhenma += new_vector[-1][0] print(yanzhenma) os.remove(name) browser.find_element_by_xpath( "/html/body/form/div/div[3]/dl[1]/dd/input").send_keys(' ') k = PyKeyboard() k.press_key(k.control_key) k.press_key('a') k.tap_key(k.delete_key) k.release_key('a') k.release_key(k.control_key) for i in yonghumin: k.tap_key(i) k.tap_key(k.tab_key) k.tap_key(k.tab_key) for i in mima: k.tap_key(i) k.tap_key(k.tab_key) for i in yanzhenma: k.tap_key(i) k.tap_key(k.enter_key)
from selenium import webdriver from time import sleep from pykeyboard import PyKeyboard from pymouse import PyMouse profile = webdriver.FirefoxProfile() profile.set_preference('browser.download.dir', 'd:\\') profile.set_preference('browser.download.folderList', 2) profile.set_preference('browser.download.manager.showWhenStarting', False) profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/zip') driver = webdriver.Firefox(firefox_profile=profile) driver.get('http://note.youdao.com/') driver.find_element_by_xpath(".//*[@id='btn-down']").click() sleep(3) # 默认在取消按钮上,先切换到保存文件上 k = PyKeyboard() # 模拟Tab k.tap_key(k.tab_key) sleep(3) # 发送Enter回车 k.tap_key(k.enter_key)
def upload_files(file_path, file, *args): # 使用pywinauto来选择文件-Desktop桌面应用程序对象 app = pywinauto.Desktop() # 选择文件上传的窗口 dlg = app['打开'] dlg.print_control_identifiers() # 选择文件地址输入框 dlg['地址: Admin'].click() k = PyKeyboard() # 输入图片文件夹地址 k.type_string(r"C:\Users\Admin\Desktop\yasuo_images") time.sleep(1) # 回车 k.press_key(k.enter_key) time.sleep(1) k.press_key(k.enter_key) time.sleep(1) # 选择文件名输入框- dlg["文件名(&N):Edit"].click() # 输入文件名时,系统默认了中文输入法,输入一个双引号会显示两个双引号 # 切换输入法 k.tap_key(k.shift_key) time.sleep(1) # 输入第一个文件名并加上双引号 k.type_string('"{}"'.format(file)) for i in args: # 输入第二个文件名并加上双引号 # 遍历不定长参数中的文件名 k.type_string('"{}"'.format(i)) time.sleep(1) # 回车时就直接打开了,不用执行 打开操作 k.press_key(k.enter_key) time.sleep(1)
class Actor(): def __init__(self): # Get the keyboard self.keyboard = PyKeyboard() # The reset button self._reset = "r" # All the keys for the game configuration self._jump = "a" self._grapple = "s" self._item = "d" self._slide = self.keyboard.down_key self._left = self.keyboard.left_key self._right = self.keyboard.right_key self._boost = self.keyboard.space_key # All the keys being used self._keys = [ self._jump, self._grapple, self._item, self._slide, self._left, self._right, self._boost ] # The last action that was taken self._last_command = "" # All of the possible actions self._actions = { 0: self.left, 1: self.left_boost, 2: self.right, 3: self.right_boost, 4: self.jump, 5: self.jump_left, 6: self.jump_left_boost, 7: self.jump_right, 8: self.jump_right_boost, 9: self.grapple, 10: self.grapple_left, 11: self.grapple_right, 12: self.item, 13: self.item_boost, 14: self.item_left, 15: self.item_left_boost, 16: self.item_right, 17: self.item_right_boost, 18: self.slide } # The number of possible actinos self.num_actions = len(self._actions) def perform_action(self, action): self._actions[action]() def reset(self): self.keyboard.press_key(self._reset) sleep(1e-2) self.keyboard.release_key(self._reset) self.release_keys() def press_keys(self, *keys): # Loop through all the keys for key in self._keys: # Press the key if it was given if (key in keys): self.keyboard.press_key(key) # Release it otherwise else: self.keyboard.release_key(key) def left(self): if (self._last_command != "left"): self.press_keys(self._left) self._last_command = "left" def left_boost(self): if (self._last_command != "left_boost"): self.press_keys(self._left, self._boost) self._last_command = "left_boost" def right(self): if (self._last_command != "right"): self.press_keys(self._right) self._last_command = "right" def right_boost(self): if (self._last_command != "right_boost"): self.press_keys(self._right, self._boost) self._last_command = "right_boost" def jump(self): if (self._last_command != "jump"): self.press_keys(self._jump) self._last_command = "jump" def jump_left(self): if (self._last_command != "jump_left"): self.press_keys(self._jump, self._left) self._last_command = "jump_left" def jump_left_boost(self): if (self._last_command != "jump_left_boost"): self.press_keys(self._jump, self._left, self._boost) self._last_command = "jump_left_boost" def jump_right(self): if (self._last_command != "jump_right"): self.press_keys(self._jump, self._right) self._last_command = "jump_right" def jump_right_boost(self): if (self._last_command != "jump_right_boost"): self.press_keys(self._jump, self._right, self._boost) self._last_command = "jump_right_boost" def grapple(self): if (self._last_command != "grapple"): self.press_keys(self._grapple) self._last_command = "grapple" def grapple_left(self): if (self._last_command != "grapple_left"): self.press_keys(self._grapple, self._left) self._last_command = "grapple_left" def grapple_right(self): if (self._last_command != "grapple_right"): self.press_keys(self._grapple, self._right) self._last_command = "grapple_right" def item(self): if (self._last_command != "item"): self.press_keys(self._item) self._last_command = "item" def item_boost(self): if (self._last_command != "item_boost"): self.press_keys(self._item, self._boost) self._last_command = "item_boost" def item_left(self): if (self._last_command != "item_left"): self.press_keys(self._item, self._left) self._last_command = "item_left" def item_left_boost(self): if (self._last_command != "item_left_boost"): self.press_keys(self._item, self._left, self._boost) self._last_command = "item_left_boost" def item_right(self): if (self._last_command != "item_right"): self.press_keys(self._item, self._right) self._last_command = "item_right" def item_right_boost(self): if (self._last_command != "item_right_boost"): self.press_keys(self._item, self._right, self._boost) self._last_command = "item_right_boost" def slide(self): if (self._last_command != "slide"): self.press_keys(self._slide) self._last_command = "slide" def release_keys(self): for key in self._keys: self.keyboard.release_key(key)
def command(speech): #here = os.path.dirname(os.path.realpath(__file__)) #os.chdir(os.path.expanduser("~/yodaqa/")) #Popen(["./gradlew","web","-q"], stdout=FNULL, stderr=FNULL) #os.chdir(here) ''' kernel = aiml.Kernel() with nostdout(): with nostderr(): kernel.learn(DRAGONFIRE_PATH + "/aiml/learn.aiml") ''' previous_command = "" global inactive global user_full_name global user_prefix global config_file while (True): line = speech.readline() if line.startswith("sentence1: ") or line.startswith( "<search failed>"): com = google_speech_api() if com == "\n" or com == " ": com = "Enter" original_com = com if (com == 0): #speech_error() continue com = com.upper() print "You: " + com if inactive == 1 and "DRAGONFIRE" != com and "DRAGON FIRE" != com and "WAKE UP" != com and com != "HEY": continue if "DRAGONFIRE" == com or "DRAGON FIRE" == com or "WAKE UP" == com or com == "HEY": tts_kill() inactive = 0 userin = Data([" "], " ") words_dragonfire = { 0: "Yes, " + user_prefix + ".", 1: "Yes. I'm waiting.", 2: "What is your orders?" } userin.say(words_dragonfire[randint(0, 2)]) elif "GO TO SLEEP" == com: tts_kill() inactive = 1 userin = Data([ "echo" ], "Dragonfire deactivated. To reactivate say 'Dragonfire!' or 'Wake Up!'" ) userin.say("I'm going to sleep") userin.interact(0) previous_command = com elif "ENOUGH" == com or "SHUT UP" == com: print "Dragonfire quiets." tts_kill() elif "WHO AM I" == com or "SAY MY NAME" == com: tts_kill() userin = Data([" "], user_full_name) userin.say("Your name is " + user_full_name + ", " + user_prefix + ".") userin.interact(0) previous_command = com elif "MY TITLE IS LADY" == com or "I'M A LADY" == com or "I'M A WOMAN" == com or "I'M A GIRL" == com: tts_kill() config_file.update({'gender': 'female'}, Query().datatype == 'gender') user_prefix = "My Lady" userin = Data([" "], " ") userin.say("Pardon, " + user_prefix + ".") elif "MY TITLE IS SIR" == com or "I'M A MAN" == com or "I'M A BOY" == com: tts_kill() config_file.update({'gender': 'male'}, Query().datatype == 'gender') user_prefix = "Sir" userin = Data([" "], " ") userin.say("Pardon, " + user_prefix + ".") elif com.startswith("CALL ME "): tts_kill() callme_config = config_file.search( Query().datatype == 'callme') if callme_config: config_file.update({'title': original_com[8:].lower()}, Query().datatype == 'callme') else: config_file.insert({ 'datatype': 'callme', 'title': original_com[8:].lower() }) user_prefix = original_com[8:].lower().encode("utf8") userin = Data([" "], " ") userin.say("Pardon, " + user_prefix + ".") elif "WHAT IS YOUR NAME" == com: tts_kill() userin = Data([" "], "My name is Dragonfire.") userin.say("My name is Dragon Fire.") userin.interact(0) previous_command = com elif "WHAT IS YOUR GENDER" == com: tts_kill() userin = Data([" "], " ") userin.say( "I have a female voice but I don't have a gender identity. I'm a computer program, " + user_prefix + ".") previous_command = com elif "FILE MANAGER" in com or "OPEN FILES" == com: tts_kill() userin = Data(["dolphin"], "File Manager") # KDE neon userin.interact(0) userin = Data(["pantheon-files"], "File Manager") # elementary OS userin.interact(0) userin = Data(["nautilus", "--browser"], "File Manager") # Ubuntu userin.say("File Manager") userin.interact(0) previous_command = com elif "WEB BROWSER" in com: tts_kill() userin = Data(["sensible-browser"], "Web Browser") userin.say("Web Browser") userin.interact(0) previous_command = com elif "OPEN BLENDER" == com: tts_kill() userin = Data(["blender"], "Blender") userin.say("Blender 3D computer graphics software") userin.interact(0) previous_command = com elif "PHOTO SHOP" in com or "PHOTO EDITOR" in com or "GIMP" in com: tts_kill() userin = Data(["gimp"], "GIMP") userin.say("Photo editor") userin.interact(0) previous_command = com elif "INKSCAPE" in com or "VECTOR GRAPHICS" in com or "VECTORIAL DRAWING" in com: tts_kill() userin = Data(["inkscape"], "Inkscape") userin.say("Inkscape") userin.interact(0) previous_command = com elif "VIDEO EDITOR" in com: tts_kill() #userin = Data(["openshot"],"Openshot") #userin.interact(0) #userin = Data(["lightworks"],"Lightworks") #userin.interact(0) userin = Data(["kdenlive"], "Kdenlive") userin.say("Video editor") userin.interact(0) previous_command = com elif "OPEN CAMERA" == com: tts_kill() userin = Data(["kamoso"], "Camera") # KDE neon userin.interact(0) userin = Data(["snap-photobooth"], "Camera") # elementary OS userin.interact(0) userin = Data(["cheese"], "Camera") # Ubuntu userin.say("Camera") userin.interact(0) previous_command = com elif "OPEN CALENDAR" == com: tts_kill() userin = Data(["korganizer"], "Calendar") # KDE neon userin.interact(0) userin = Data(["maya-calendar"], "Calendar") # elementary OS userin.interact(0) userin = Data(["orage"], "Calendar") # Ubuntu userin.say("Calendar") userin.interact(0) previous_command = com elif "OPEN CALCULATOR" == com: tts_kill() userin = Data(["kcalc"], "Calculator") # KDE neon userin.interact(0) userin = Data(["pantheon-calculator"], "Calculator") # elementary OS userin.interact(0) userin = Data(["gnome-calculator"], "Calculator") # Ubuntu userin.say("Calculator") userin.interact(0) previous_command = com elif "OPEN STEAM" == com: tts_kill() userin = Data(["steam"], "Steam") userin.say("Steam Game Store") userin.interact(0) previous_command = com elif "SOFTWARE CENTER" in com: tts_kill() userin = Data(["plasma-discover"], "Software Center") # KDE neon userin.interact(0) userin = Data(["software-center"], "Software Center") # elementary OS & Ubuntu userin.say("Software Center") userin.interact(0) previous_command = com elif "OFFICE SUITE" in com: tts_kill() userin = Data(["libreoffice"], "LibreOffice") userin.say("Office Suite") userin.interact(0) previous_command = com elif "OPEN WRITER" == com: tts_kill() userin = Data(["libreoffice", "--writer"], "LibreOffice Writer") userin.say("Writer") userin.interact(0) previous_command = com elif "OPEN MATH" == com: tts_kill() userin = Data(["libreoffice", "--math"], "LibreOffice Math") userin.say("Math") userin.interact(0) previous_command = com elif "OPEN IMPRESS" == com: tts_kill() userin = Data(["libreoffice", "--impress"], "LibreOffice Impress") userin.say("Impress") userin.interact(0) previous_command = com elif "OPEN DRAW" == com: tts_kill() userin = Data(["libreoffice", "--draw"], "LibreOffice Draw") userin.say("Draw") userin.interact(0) previous_command = com elif com.startswith("KEYBOARD "): tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() for character in original_com[9:]: k.tap_key(character) k.tap_key(" ") elif com == "ENTER": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.tap_key(k.enter_key) elif com == "NEW TAB": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.control_l_key, 't']) elif com == "SWITCH TAB": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.control_l_key, k.tab_key]) elif com == "CLOSE" or com == "ESCAPE": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.control_l_key, 'w']) k.tap_key(k.escape_key) elif com == "GO BACK": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.alt_l_key, k.left_key]) elif com == "GO FORWARD": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.alt_l_key, k.right_key]) elif com == "SCROLL LEFT": tts_kill() with nostdout(): with nostderr(): m = PyMouse() m.scroll(0, -5) elif com == "SCROLL RIGHT": tts_kill() with nostdout(): with nostderr(): m = PyMouse() m.scroll(0, 5) elif com == "SCROLL UP": tts_kill() with nostdout(): with nostderr(): m = PyMouse() m.scroll(5, 0) elif com == "SCROLL DOWN": tts_kill() with nostdout(): with nostderr(): m = PyMouse() m.scroll(-5, 0) elif com == "PLAY" or com == "PAUSE" or com == "SPACEBAR": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.tap_key(" ") elif "SHUTDOWN THE COMPUTER" == com: tts_kill() userin = Data(["sudo", "poweroff"], "Shutting down") userin.say("Shutting down") userin.interact(3) previous_command = com elif com == "GOODBYE" or com == "BYE BYE" or com == "SEE YOU LATER": tts_kill() userin = Data([" "], " ") userin.say("Goodbye, " + user_prefix) previous_command = com julius_proc.terminate() with nostdout(): with nostderr(): try: os.system('rm -f /tmp/' + str(datetime.date.today().year) + '*.[Ww][Aa][Vv]') except: pass sys.exit(1) elif "WIKIPEDIA" in com and ("SEARCH" in com or "FIND" in com): tts_kill() with nostdout(): with nostderr(): capture = re.search( "(?:SEARCH|FIND) (?P<query>.*) (?:IN|ON|AT|USING)? WIKIPEDIA", com) if capture: search_query = capture.group('query') try: wikipage = wikipedia.page( wikipedia.search(search_query)[0]) wikicontent = "".join([ i if ord(i) < 128 else ' ' for i in wikipage.content ]) wikicontent = re.sub(r'\([^)]*\)', '', wikicontent) userin = Data( ["sensible-browser", wikipage.url], search_query) userin.interact(0) userin.say(wikicontent) previous_command = com except: pass elif "YOUTUBE" in com and ("SEARCH" in com or "FIND" in com): tts_kill() with nostdout(): with nostderr(): capture = re.search( "(?:SEARCH|FIND) (?P<query>.*) (?:IN|ON|AT|USING)? YOUTUBE", com) if capture: search_query = capture.group('query') info = youtube_dl.YoutubeDL({}).extract_info( 'ytsearch:' + search_query, download=False, ie_key='YoutubeSearch') if len(info['entries']) > 0: youtube_title = info['entries'][0]['title'] youtube_url = "https://www.youtube.com/watch?v=%s" % ( info['entries'][0]['id']) userin = Data( ["sensible-browser", youtube_url], youtube_title) youtube_title = "".join([ i if ord(i) < 128 else ' ' for i in youtube_title ]) else: youtube_title = "No video found, " + user_prefix + "." userin = Data(" ", " ") userin.say(youtube_title) userin.interact(0) time.sleep(5) k = PyKeyboard() k.tap_key(k.tab_key) k.tap_key(k.tab_key) k.tap_key(k.tab_key) k.tap_key(k.tab_key) k.tap_key('f') else: tts_kill() #dragonfire_respond = kernel.respond(com) aiml_respond = learn_.respond(com) if aiml_respond: userin = Data([" "], " ") userin.say(aiml_respond) #if aiml_respond and "WHAT" not in aiml_respond and "WHERE" not in aiml_respond and "WHO" not in aiml_respond and "WHEN" not in aiml_respond and "WHICH" not in aiml_respond and "HOW" not in aiml_respond: # userin.say(aiml_respond) #else: # userin.say("I need to do a brief research on the internet. It may take up to 3 minutes, so please be patient.") # userin.say(YodaQA.answer("http://qa.ailao.eu", original_com, user_prefix)) previous_command = com
def command(com, args, tw_user=None): global e if (e.is_set()): # System Tray Icon exit must trigger this exit(0) if not com or not isinstance(com, str): return False original_com = com global inactive global user_full_name global user_prefix global config_file userin.twitter_user = tw_user com = com.upper() print("You: " + com) if inactive and com not in ("DRAGONFIRE", "DRAGON FIRE", "WAKE UP", "HEY"): return True if USER_ANSWERING['status']: if com.startswith("FIRST") or com.startswith( "THE FIRST") or com.startswith("SECOND") or com.startswith( "THE SECOND") or com.startswith( "THIRD") or com.startswith("THE THIRD"): USER_ANSWERING['status'] = False selection = None if com.startswith("FIRST") or com.startswith("THE FIRST"): selection = 0 elif com.startswith("SECOND") or com.startswith("THE SECOND"): selection = 1 elif com.startswith("THIRD") or com.startswith("THE THIRD"): selection = 2 if USER_ANSWERING['for'] == 'wikipedia': with nostderr(): search_query = USER_ANSWERING['options'][selection] try: wikiresult = wikipedia.search(search_query) if len(wikiresult) == 0: userin.say( "Sorry, " + user_prefix + ". But I couldn't find anything about " + search_query + " in Wikipedia.") return True wikipage = wikipedia.page(wikiresult[0]) wikicontent = "".join([ i if ord(i) < 128 else ' ' for i in wikipage.content ]) wikicontent = re.sub(r'\([^)]*\)', '', wikicontent) userin.define_and_execute( ["sensible-browser", wikipage.url], search_query) userin.say(wikicontent) return True except requests.exceptions.ConnectionError: userin.define_and_execute( [" "], "Wikipedia connection error.") userin.say( "Sorry, " + user_prefix + ". But I'm unable to connect to Wikipedia servers.") return True except Exception: return True if com in ("DRAGONFIRE", "DRAGON FIRE", "WAKE UP", "HEY"): tts_kill() inactive = False userin.define([" "], " ") words_dragonfire = ("Yes, " + user_prefix + ".", "Yes. I'm waiting.", "What is your order?") userin.say(choice(words_dragonfire)) elif "GO TO SLEEP" == com: tts_kill() inactive = True userin.define_and_execute( ["echo"], "Dragonfire deactivated. To reactivate say 'Dragonfire!' or 'Wake Up!'") userin.say("I'm going to sleep") elif com in ("ENOUGH", "SHUT UP"): print("Dragonfire quiets.") tts_kill() elif VirtualAssistant.exact_match(com): return True # the request has been handled elif VirtualAssistant.in_match(com): return True # the request has been handled elif ("SEARCH" in com or "FIND" in com) and VirtualAssistant.search_command(com): pass # the request has been handled elif com in ("MY TITLE IS LADY", "I'M A LADY", "I'M A WOMAN", "I'M A GIRL"): tts_kill() config_file.update({ 'gender': 'female' }, Query().datatype == 'gender') user_prefix = "My Lady" userin.define([" "], " ") userin.say("Pardon, " + user_prefix + ".") elif com in ("MY TITLE IS SIR", "I'M A MAN", "I'M A BOY"): tts_kill() config_file.update({ 'gender': 'male' }, Query().datatype == 'gender') user_prefix = "Sir" userin.define([" "], " ") userin.say("Pardon, " + user_prefix + ".") elif com.startswith("CALL ME "): tts_kill() callme_config = config_file.search(Query().datatype == 'callme') if callme_config: config_file.update({ 'title': original_com[8:].lower() }, Query().datatype == 'callme') else: config_file.insert({ 'datatype': 'callme', 'title': original_com[8:].lower() }) user_prefix = original_com[8:].lower().encode("utf8") userin.define([" "], " ") userin.say("Pardon, " + user_prefix + ".") # only for The United States today but prepared for all countries. Also # only for celsius degrees today. --> by Radan Liska :-) elif "WHAT" in com and "TEMPERATURE" in com: tts_kill() capture = re.search( "(?:WHAT IS|WHAT'S) THE TEMPERATURE (?:IN|ON|AT|OF)? (?P<city>.*)", com) if capture: city = capture.group('city') owm = pyowm.OWM("16d66c84e82424f0f8e62c3e3b27b574") reg = owm.city_id_registry() weather = owm.weather_at_id( reg.ids_for(city)[0][0]).get_weather() fmt = "The temperature in {} is {} degrees celsius" msg = fmt.format(city, weather.get_temperature('celsius')['temp']) userin.define_and_execute([" "], msg) userin.say(msg) elif "FILE MANAGER" in com or "OPEN FILES" == com: tts_kill() userin.define_and_execute(["dolphin"], "File Manager") # KDE neon userin.define_and_execute(["pantheon-files"], "File Manager") # elementary OS userin.define_and_execute(["nautilus", "--browser"], "File Manager") # Ubuntu userin.say("File Manager") elif "OPEN CAMERA" == com: tts_kill() userin.define_and_execute(["kamoso"], "Camera") # KDE neon userin.define_and_execute(["snap-photobooth"], "Camera") # elementary OS userin.define_and_execute(["cheese"], "Camera") # Ubuntu userin.say("Camera") elif "OPEN CALENDAR" == com: tts_kill() userin.define_and_execute(["korganizer"], "Calendar") # KDE neon userin.define_and_execute(["maya-calendar"], "Calendar") # elementary OS userin.define_and_execute(["orage"], "Calendar") # Ubuntu userin.say("Calendar") elif "OPEN CALCULATOR" == com: tts_kill() userin.define_and_execute(["kcalc"], "Calculator") # KDE neon userin.define_and_execute(["pantheon-calculator"], "Calculator") # elementary OS userin.define_and_execute(["gnome-calculator"], "Calculator") # Ubuntu userin.say("Calculator") elif "SOFTWARE CENTER" in com: tts_kill() userin.define_and_execute(["plasma-discover"], "Software Center") # KDE neon userin.define_and_execute( ["software-center"], "Software Center") # elementary OS & Ubuntu userin.say("Software Center") elif com.startswith("KEYBOARD "): tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() for character in original_com[9:]: k.tap_key(character) k.tap_key(" ") elif com == "ENTER": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.tap_key(k.enter_key) elif com == "NEW TAB": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.control_l_key, 't']) elif com == "SWITCH TAB": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.control_l_key, k.tab_key]) elif com in ("CLOSE", "ESCAPE"): tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.control_l_key, 'w']) k.tap_key(k.escape_key) elif com == "GO BACK": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.alt_l_key, k.left_key]) elif com == "GO FORWARD": tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.press_keys([k.alt_l_key, k.right_key]) elif com == "SCROLL LEFT": tts_kill() with nostdout(): with nostderr(): m = PyMouse() m.scroll(0, -5) elif com == "SCROLL RIGHT": tts_kill() with nostdout(): with nostderr(): m = PyMouse() m.scroll(0, 5) elif com == "SCROLL UP": tts_kill() with nostdout(): with nostderr(): m = PyMouse() m.scroll(5, 0) elif com == "SCROLL DOWN": tts_kill() with nostdout(): with nostderr(): m = PyMouse() m.scroll(-5, 0) elif com in ("PLAY", "PAUSE", "SPACEBAR"): tts_kill() with nostdout(): with nostderr(): k = PyKeyboard() k.tap_key(" ") elif "SHUTDOWN THE COMPUTER" == com: tts_kill() userin.define(["sudo", "poweroff"], "Shutting down") userin.say("Shutting down") userin.execute(3) elif com in ("GOODBYE", "GOOD BYE", "BYE BYE", "SEE YOU LATER", "CATCH YOU LATER"): tts_kill() userin.define([" "], " ") userin.say("Goodbye, " + user_prefix) # raise KeyboardInterrupt thread.interrupt_main() elif "WIKIPEDIA" in com and ("SEARCH" in com or "FIND" in com): tts_kill() with nostderr(): capture = re.search( "(?:SEARCH|FIND) (?P<query>.*) (?:IN|ON|AT|USING)? WIKIPEDIA", com) if capture: search_query = capture.group('query') try: wikiresult = wikipedia.search(search_query) if len(wikiresult) == 0: userin.say("Sorry, " + user_prefix + ". But I couldn't find anything about " + search_query + " in Wikipedia.") return True wikipage = wikipedia.page(wikiresult[0]) wikicontent = "".join([ i if ord(i) < 128 else ' ' for i in wikipage.content ]) wikicontent = re.sub(r'\([^)]*\)', '', wikicontent) userin.define_and_execute( ["sensible-browser", wikipage.url], search_query) userin.say(wikicontent) except requests.exceptions.ConnectionError: userin.define_and_execute( [" "], "Wikipedia connection error.") userin.say( "Sorry, " + user_prefix + ". But I'm unable to connect to Wikipedia servers." ) except wikipedia.exceptions.DisambiguationError as disambiguation: USER_ANSWERING['status'] = True USER_ANSWERING['for'] = 'wikipedia' USER_ANSWERING['reason'] = 'disambiguation' USER_ANSWERING['options'] = disambiguation.options[:3] notify = "Wikipedia disambiguation. Which one of these you meant?:\n - " + \ disambiguation.options[0] message = user_prefix + ", there is a disambiguation. Which one of these you meant? " + \ disambiguation.options[0] for option in disambiguation.options[1:3]: message += ", or " + option notify += "\n - " + option notify += '\nSay, for example: "THE FIRST ONE" to choose.' userin.define_and_execute([" "], notify) userin.say(message) except BaseException: pass elif "YOUTUBE" in com and ("SEARCH" in com or "FIND" in com): tts_kill() with nostdout(): with nostderr(): capture = re.search( "(?:SEARCH|FIND) (?P<query>.*) (?:IN|ON|AT|USING)? YOUTUBE", com) if capture: search_query = capture.group('query') info = youtube_dl.YoutubeDL({}).extract_info( 'ytsearch:' + search_query, download=False, ie_key='YoutubeSearch') if len(info['entries']) > 0: youtube_title = info['entries'][0]['title'] youtube_url = "https://www.youtube.com/watch?v=%s" % ( info['entries'][0]['id']) userin.define(["sensible-browser", youtube_url], youtube_title) youtube_title = "".join([ i if ord(i) < 128 else ' ' for i in youtube_title ]) else: youtube_title = "No video found, " + user_prefix + "." userin.define(" ", " ") userin.execute(0) userin.say(youtube_title) time.sleep(5) k = PyKeyboard() k.tap_key(k.tab_key) k.tap_key(k.tab_key) k.tap_key(k.tab_key) k.tap_key(k.tab_key) k.tap_key('f') elif ("GOOGLE" in com or "WEB" in com) and "IMAGE" not in com and ("SEARCH" in com or "FIND" in com): tts_kill() with nostdout(): with nostderr(): capture = re.search( "(?:SEARCH|FIND) (?P<query>.*) (?:IN|ON|AT|USING)? (?:GOOGLE|WEB)?", com) if capture: search_query = capture.group('query') tab_url = "http://google.com/?#q=" + search_query userin.define_and_execute( ["sensible-browser", tab_url], search_query) userin.say(search_query) elif ("GOOGLE" in com or "WEB" in com) and "IMAGE" in com and ("SEARCH" in com or "FIND" in com): tts_kill() with nostdout(): with nostderr(): capture = re.search("(?:SEARCH IMAGES OF|FIND IMAGES OF|SEARCH|FIND) " "(?P<query>.*) (?:IN|ON|AT|USING)? " "(?:GOOGLE|WEB|GOOGLE IMAGES|WEB IMAGES)?", com) if capture: search_query = capture.group('query') tab_url = "http://google.com/?#q=" + search_query + "&tbm=isch" userin.define(["sensible-browser", tab_url], search_query) userin.execute(0) userin.say(search_query) else: tts_kill() learn_response = learn_.respond(original_com) if learn_response: userin.define([" "], " ") userin.say(learn_response) else: omniscient_.respond(original_com, not args["silent"], userin, user_prefix, args["twitter"])
# The online help is located at "https://help.gnome.org/users/eog/stable/" # For keyboard shortcut is located at "https://help.gnome.org/users/eog/stable/shortcuts.html.en" # # NOTE: If you are not administrator user it is necessary to add the suffix "sudo" # before the "apt-get" command # #==================================================================================================== import RPi.GPIO as GPIO import MGC3130 import threading import time from pykeyboard import PyKeyboard KeyPressed = PyKeyboard() #========================================================== # Define pin Addr_MGC3130 = 0x42 # MGC3130 hardware address MGC3130_SDA_LINE = 2 MGC3130_SCL_LINE = 3 MGC3130_TS_LINE = 18 MGC3130_RESET_LINE = 17 JUMPER_J1 = 24 PULSE_P1 = 23 PULSE_P2 = 22 PULSE_P3 = 27
class Keys: def __init__(self): self.k = PyKeyboard() # self.suppress_xlib_output(2) def press_tab(self, num=1): for i in range(num): self.k.tap_key(self.k.tab_key) def press_home_key(self, num=1): for i in range(num): self.k.tap_key(self.k.home_key) def press_end_key(self, num=1): for i in range(num): self.k.tap_key(self.k.end_key) def press_enter(self): self.k.tap_key(self.k.enter_key) def hold_key(self, key, t=1): self.k.press_key(key) sleep(t) self.k.release_key(key) def hold_down(self, t=1): self.hold_key(self.k.down_key, t) def press_down(self, num=1): for i in range(num): self.k.tap_key(self.k.down_key) def press_right(self, num=1): for i in range(num): self.k.tap_key(self.k.right_key) def press_left(self, num=1): for i in range(num): self.k.tap_key(self.k.left_key) def press_up(self, num=1): for i in range(num): self.k.tap_key(self.k.up_key) def press_esc(self): self.k.tap_key(self.k.escape_key) def send_text(self, text): text = str(text) for letter in text: self.k.tap_key(letter) def press_ctrl_enter(self, num=1): for i in range(num): self.k.press_key(self.k.control_key) self.press_enter() self.k.release_key(self.k.control_key) def press_ctrl_tab(self, num=1): for i in range(num): self.k.press_key(self.k.control_key) self.press_tab() self.k.release_key(self.k.control_key) def press_ctrl_w(self, num=1): for i in range(num): self.k.press_key(self.k.control_key) self.k.tap_key('w') self.k.release_key(self.k.control_key) def press_shift_left(self, num=1): for i in range(num): self.k.press_key(self.k.shift_key) self.k.tap_key(self.k.left_key) self.k.release_key(self.k.shift_key) def press_shift_tab(self, num=1): for i in range(num): self.k.press_key(self.k.shift_key) self.k.tap_key(self.k.tab_key) self.k.release_key(self.k.shift_key) def press_alt_tab(self, num=1): for i in range(num): self.k.press_key(self.k.alt_key) self.press_tab() self.k.release_key(self.k.alt_key) def press_ctrl_alt_and(self, f, num=1): for i in range(num): self.k.press_key(self.k.control_key) self.k.press_key(self.k.alt_key) f() self.k.release_key(self.k.alt_key) self.k.release_key(self.k.control_key) def press_ctrl_alt_up(self, num=1): self.press_ctrl_alt_and(self.press_up, num) def press_ctrl_alt_down(self, num=1): self.press_ctrl_alt_and(self.press_down, num) def press_ctrl_alt_right(self, num=1): self.press_ctrl_alt_and(self.press_right, num) def press_ctrl_alt_left(self, num=1): self.press_ctrl_alt_and(self.press_left, num) def press_ctrl_and(self, letter, num=1): assert type(letter) is str, 'The letter has to be a string' for i in range(num): self.k.press_key(self.k.control_key) self.k.tap_key(letter) self.k.release_key(self.k.control_key) def press_space(self): self.k.tap_key(' ') def type(self, txt): self.k.type_string(txt) @staticmethod def suppress_xlib_output(num): for i in range(num): print '\r\033[1A' + 46 * ' ', print '\r'
from pykeyboard import PyKeyboard import time k = PyKeyboard() # s = "c:\hello.txt" # for j in s: k.type_string('c:\hello.txt') # k.tab_key("h") # time.sleep(2) # k.tab_key(k.enter_key)#回车
play_button = (1617, 963) # Inset here the coordinates to get the tree branches, # in format (x, 0, x+1, y), where # x - the X "axis" that sections/cut the branches # y - Any pixel below the lowest branch (in case of doubt, # put the height of the screen, in pixels) bbox = (1554, 0, 1555, 671) # Insert here the Y coordinates to look for the branches. You HAVE to put six # values. If you can't see 6 branches at time on your screen, try to zoom out # the browser. Usually, the values will be equally spaced. heights = [170, 270, 370, 470, 570, 670] mouse = PyMouse() keyboard = PyKeyboard() def right(): keyboard.tap_key(keyboard.right_key) def left(): keyboard.tap_key(keyboard.left_key) def play(): x, y = play_button mouse.click(x, y, 1)
# coding:utf-8 from selenium import webdriver from common.base import Base from pykeyboard import PyKeyboard from common.testDate import enterInfo as i import time k = PyKeyboard() """ page/orderBatch.py """ class orgOperation(Base): # inherit Base # locator path loanButton = ("xpath", ".//span[contains(text(),'申请垫资(保理一 / 保理二 / 投保单)')]") businessMode = ("xpath", ".//div[@class='_item'][2]") importExcel = ( "xpath", ".//*[@class='el-button el-button--primary el-button--mini']") creditorUserName = ( "xpath", "//*[@class='l-creditor-list']/div/div[1]/div/div/input") creditorPhone = ("xpath", "//*[@class='l-creditor-list']/div/div[2]/div/div/input") creditorIdCard = ("xpath", "//*[@class='l-creditor-list']/div/div[3]/div/div/input") creditorAmount = ("xpath", "//*[@class='l-creditor-list']/div/div[4]/div/div/input") contractName = ("xpath", "//*[@class='l-creditor-list']/div/div[5]/div/div/input") contractDate = ("xpath", "//*[@class='l-creditor-list']/div/div[6]/div/div/input")
class UiAction: def __init__(self, driver, host): self.driver = driver self.host = host self.page = Page(driver) self.logger = Logger.get_logger() self.match = ImageMatch() self.mouse = PyMouse() self.keyboard = PyKeyboard() def open_browser(self, uri): # 注意:一定要把项目的host部分独立出来,方便未来测试的时候切换环境 url = self.host + uri self.driver.get(url) self.logger.info(f'打开浏览器访问被测网站{url}。') def input_text(self, locator, content): element = self.page.get_element(locator) element.clear() element.send_keys(content) self.logger.info(f'在{locator}元素上输入{content}。') def input_password(self, locator, password): self.input_text(locator, password) def click_element(self, locator): self.page.get_element(locator).click() self.logger.info(f'在{locator}元素上单击一次。') def set_implicitly_wait(self, timeout): self.driver.implicitly_wait(timeout) self.logger.info(f'设置全局隐式等待时间为{timeout}秒。') def wait_until_element_contains(self, locator, content, timeout=5): # 针对指定的元素进行等待,如果等待成功,那么获得该元素对象,并去按指定条件进行检查, # 满足则返回True;不满足,则返回Flase。 if self.page.wait_until_element(locator, float(timeout)): self.logger.info(f'等待元素{locator}包含{content}内容出现。') return content in self.page.get_element(locator).text self.logger.warn(f'没有等到指定{locator}元素。') return False def input_text_by_template(self, target, content): x, y = self.click_by_template(target) self.keyboard.type_string(str(content)) self.logger.info(f'在指定元素{target}对象中输入{content}。') def click_by_template(self, target): x, y = self.match.find_image(target) if x == -1 or y == -1: self.logger.error(f'没有找到指定的元素{target}对象。') raise NoSuchElementException self.mouse.click(x, y) self.logger.info(f'在指定元素{target}对象上单击。') return x, y def capture_screen(self, filename): # 构造截图的默认路径 screen_path = Project.get_resource_path('report/screenshot') self.driver.get_screenshot_as_file(os.path.join(screen_path, filename)) self.logger.info(f'截取当前画面并保存为文件{filename}。') # 注意这里返回的是图片文件的相对路径 return f'screenshot/{filename}' def element_should_contains(self, locator, expected): # 这里利用了python内置的断言语句assert,该语句的用法如下: # assert conditional, error_message # conditional表示条件,其值必须是布尔类型 # error_message是当断言错误时会显示的消息 # 在一个方法中有多个断言语句assert的时候,那么多个语句的关系是逻辑与的关系。 assert self.page.element_is_exists( locator), f'断言错误:指定的元素{locator}对象没找到。' actual = self.page.get_element(locator).text assert expected in actual, f'断言错误:实际测试结果{actual}中不包含预期的值{expected}。'
# install from https://github.com/PyUserInput/PyUserInput from pykeyboard import PyKeyboard from integriot import * kb = PyKeyboard() def inject_key(key, msg): global kb if msg == "1": kb.press_key(key) else: kb.release_key(key) def up_cb(msg): inject_key(kb.up_key, msg) def left_cb(msg): inject_key(kb.left_key, msg) def down_cb(msg): inject_key(kb.down_key, msg) def right_cb(msg): inject_key(kb.right_key, msg)
from pymouse import PyMouse from pykeyboard import PyKeyboard import time m = PyMouse() k = PyKeyboard() # m.drag(400, 400) # for i in range(x_dim): # for j in range(y_dim): # time.sleep(0.1) # m.move(i, j) # m.scroll(vertical=1) # time.sleep(1) # m.scroll(vertical=1) # m.click(x_dim/2, y_dim/2, 1) # k.type_string('Hello, World!') # # pressing a key # k.press_key('H') # # which you then follow with a release of the key # k.release_key('H') # # or you can 'tap' a key which does both # k.tap_key('e') # # note that that tap_key does support a way of repeating keystrokes with a interval time between each # k.tap_key('l',n=2,interval=5) # # and you can send a string if needed too # k.type_string('o World!') def alt_tab(): k.press_key(k.alt_key) k.tap_key(k.tab_key) k.release_key(k.alt_key)
def test001_upload(self): url = "https://www.layui.com/demo/upload.html" browser = webdriver.Chrome() # 访问图片上传的URL browser.get(url=url) # 点击图片上传按钮,打开文件选择窗口 browser.find_element_by_xpath("//*[@id='test1']").click() # 使用pywinauto来选择文件-Desktop桌面应用程序对象 app = pywinauto.Desktop() # 选择文件上传的窗口 dlg = app['打开'] dlg.print_control_identifiers() # 选择文件地址输入框 dlg['地址: Admin'].click() k = PyKeyboard() # 输入图片文件夹地址(可以直接输入图片地址后回车,考虑到后期使用时可以作为两个变量,就分两步走) # k.type_string(r'C:\Users\Admin\Desktop\亚索图片\2.jpg') # type_string不支持中文,建议改成英文文件夹名称 k.type_string(r"C:\Users\Admin\Desktop\yasuo_images") time.sleep(1) # 回车 k.press_key(k.enter_key) time.sleep(1) k.press_key(k.enter_key) time.sleep(1) # 选择文件名输入框 dlg["文件名(&N):Edit"].click() k.type_string('2.jpg') # 回车 k.press_key(k.enter_key) # 点击 打开 dlg['打开(&O)'].click()
def start(self): self.k = PyKeyboard() pdf = self.PdfThread() pdf.start()