async def record_keyboard( controller_state: ControllerState ): #this method binds keyboard to conroller and records input for later playback if controller_state.get_controller() != Controller.PRO_CONTROLLER: raise ValueError('This script only works with the Pro Controller!') # waits until controller is fully connected await controller_state.connect() print('Using only letters and numbers, type a name for this recording') print('Then press <enter> to start recording keyboard control.') recordingName = await ainput(prompt='Recording name:') #pixels = neopixel.NeoPixel(board.D12, 6, auto_write=False) #button state handler callbacks savedRecordings = shelve.open('savedRecs', writeback=True) LeftStick = controller_state.l_stick_state RightStick = controller_state.r_stick_state bindKeyboard(controller_state) keyboard.start_recording() pixels.fill((0, 0, 0)) pixels.fill((10, 0, 0)) pixels.fill((10, 0, 0)) await ainput( prompt='Press <enter> to stop recording and exit keyboard control.') recording = keyboard.stop_recording() pixels.fill((0, 0, 0)) pixels.fill((0, 0, 0)) keyboard.unhook_all() savedRecordings[recordingName] = recording savedRecordings.close() ControllerCLI._set_stick(RightStick, 'center', None) ControllerCLI._set_stick(LeftStick, 'center', None) await controller_state.send()
def beat(self): keyboard.start_recording(recorded_events_queue=None) time.sleep(self.stepWait) pressedKeys = keyboard.stop_recording() for pK in reversed(pressedKeys): if pK.name in self.dirKeys: return pK.name
def replay(): # pyautogui.moveTo(width/2,height/2) #move mouse to middle of screen time.sleep(.2) base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) keyboard.start_recording() keyboard.stop_recording() mouse_events = pickle.load(open(base_dir +r'/events/mouse.p','rb')) keyboard_events = pickle.load(open(base_dir +r'/events/keyboard.p','rb')) print(keyboard_events) #Keyboard threadings: k_thread = threading.Thread(target = lambda :keyboard.play(keyboard_events[:-1])) k_thread.start() #Mouse threadings: m_thread = threading.Thread(target = lambda :mouse.play(mouse_events)) m_thread.start() #waiting for both threadings to be completed m_thread.join() k_thread.join()
def recordSkill(): keyboard.start_recording() time.sleep(5) eventlist = keyboard.stop_recording() i = 0 first_time = 0 print("event_list = []") if eventlist[0].event_type == "down" and eventlist[0].name == 'x': global practice global replay_state practice = bool(1 - practice) replay_state = bool(1 - replay_state) print("Practice state") else: for e in eventlist: if first_time == 0: first_time = e.time t = e.time - first_time print( "event_list.append(keyboard.KeyboardEvent('{}', {}, name='{}',time = {}, modifiers={}, is_keypad={}))" .format(e.event_type, e.scan_code, e.name, round(t, 2), False, False)) print("keyboard.play(event_list)") keyboard.play(eventlist)
def get_key_stroke(): keyevents = keyboard.stop_recording() keyboard.start_recording() keylist = [] for event in keyevents: if event.event_type == "down": if event.name not in keylist: keylist.append(event.name.lower()) return keylist
def speed_test(): # s1 = psutil.net_io_counters(pernic=True)['无线网络连接'] keyboard.start_recording() time.sleep(1) # s2 = psutil.net_io_counters(pernic=True)['无线网络连接'] s = keyboard.stop_recording() # result = s2.bytes_recv - s1.bytes_recv speed = len(s) // 2 return str(speed) + 'char/s'
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 toggle_record_new_hotkey(): global window, recording, hotkey, keyboard_recording, new_hotkey_btn, show_hotkey, toggle_hotkey, is_on is_on = False # If grumby is in recoring mode if recording: recording = False keyboard_recording = keyboard.stop_recording() new_hotkey_btn['text'] = "Change Hotkey" change_background("deactivated") modifiers = [] # The keyboard library records all keys pressed while grumby is in recording mode # This loop parses for any modifier keys that have been pressed (excluding the windows key) # As well as the last char charachter pressed. All other key presses are disguarded. print(f"\n\n\nkeyboard recording: {keyboard_recording}\n\n\n") for keypress in keyboard_recording: print(f"\nkeypress {keypress.name}\n") if keypress.name in ('shift', 'ctrl', 'alt'): if keypress.name not in (modifiers): modifiers.append(keypress.name) if keypress.name not in ('shift', 'ctrl', 'alt', 'windows', 'esc', 'unknown'): pressed_key = keypress.name if len(modifiers) > 0: new_hotkey = "+".join(modifiers) + "+" + pressed_key else: # If no keypresses were entered while grumby was in recording mode try: new_hotkey = pressed_key except: pass keyboard_recording = None # If the pressed keys were valid then modify the hotkey an ui, else reset to previously set hotkey try: toggle_hotkey = keyboard.add_hotkey(new_hotkey, toggle_grumby) hotkey = new_hotkey new_show_hotkey_text = f"Toggle Grumby with '{hotkey}'" if len(new_show_hotkey_text) < 30: show_hotkey['text'] = new_show_hotkey_text else: show_hotkey['text'] = f"Toggle Grumby with\n'{hotkey}'" except: messagebox.showinfo( "*Wiggles Mustache*", "No keypresses were recorded.\nNo changes were made.\n\nPress multiple keys at the same time. For example: 'ctrl+shift+m' or 'alt+a'" ) toggle_hotkey = keyboard.add_hotkey(hotkey, toggle_grumby) save_grumby_state() # If grumby is not in recording mode, then change ui and start recording else: recording = True keyboard.remove_hotkey(toggle_hotkey) new_hotkey_btn['text'] = "Press To Stop" change_background("recording") keyboard.start_recording()
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 get_one_datapoint(self): prev_time = now() recording = keyboard.start_recording() while True: sleep(0.01) # progress bar implementation in the middle of this code... progress = ''.join(['='] * len(list(recording[0].queue))) empty = ''.join([' '] * (self.warmup + self.slice + self.cooldown - len(list(recording[0].queue)))) print('\r' + '[' + progress + empty + ']', end='') if (len(list(recording[0].queue)) >= self.warmup + self.slice + self.cooldown): recorded = keyboard.stop_recording() break times = [] for k in recorded: times.append(k.time - prev_time) prev_time = k.time X = np.array(times) X = X[self.warmup:] X = X[:-self.cooldown] X = X[:self.slice] X = np.reshape(X, (self.slice, 1)) return X
def record(): k.start_recording() positions = [] i = 0 while True: positions.append( (m.X, m.X2, m.is_pressed(button='left'), m.is_pressed(button='right'), m.is_pressed(button='middle'))) p.screenshot('frames/{}.png'.format(i)) if k.is_pressed('escape'): break sleep(sample_rate) i += 1 keys = k.stop_recording() print(positions) print(keys)
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 record(self): keyboard.start_recording() time.sleep(0.2) recorded = keyboard.stop_recording() try: action = recorded[0].name except IndexError: action = None if action == 'right': self.action = 2 elif action == 'left': self.action = 3 elif action == 'up': self.action = 1 else: self.action = 0
def main(): mouse_minute_data = {} keyboard_minute_data = {} mins = int(input('How many minutes would you like to analyze? ')) print() i = 0 while i < mins: mouse_events = [] mouse.hook(mouse_events.append) keyboard.start_recording() time.sleep(60) mouse.unhook(mouse_events.append) keyboard_events = keyboard.stop_recording() mouse_minute_data[i + 1] = len(mouse_events) keyboard_minute_data[i + 1] = len(keyboard_events) i += 1 for (mouse_minute, mouse_data), (keyboard_minute, keyboard_data) in zip(mouse_minute_data.items(), keyboard_minute_data.items()): print('Minute ', mouse_minute, ':') print(mouse_data, 'mouse events') print(keyboard_data, 'keyboard events') print() plt.plot(mouse_minute_data.keys(), mouse_minute_data.values(), color='red', label='Mouse Events') plt.plot(keyboard_minute_data.keys(), keyboard_minute_data.values(), color='blue', label='Keyboard Events') plt.title('Productivity Analysis') plt.xlabel('Minutes') plt.ylabel('Events per minute') plt.legend() plt.show()
def record(self, escape_key="esc"): """ Records all the key press and mouse movements and return a list of recorded events. Pressing the escape_key stops the recording. Returns the recorded events. """ self.stop_replay = False mouse.hook(self.mouse_events_queue.put) keyboard.start_recording(self.keyboard_events_queue) print("Recoding until esc is pressed...") keyboard.wait(escape_key) mouse.unhook(self.mouse_events_queue.put) keyboard.stop_recording() events_queue = self.merge(self.mouse_events_queue, self.keyboard_events_queue) self.events = list(events_queue.queue) print("Recording completed.") return self.events
def __init__(self): super().__init__() self.time_completed = None print("starting time: ", time.time()) self.window_getter = WindowInfoGetter().start() # self.screen_recorder = ScreenRecorder().start() self.video_getter = VideoGet().start() self.df = pd.DataFrame() self.listener_mouse = mouse.Listener(on_move=self.on_move, on_click=self.on_click, on_scroll=self.on_scroll, suppress=False) self.listener_mouse.start() self.LEFT_KEY_PRESSED_FLAG = False self.SCREEN_WIDTH, self.SCREEN_HEIGHT = auto.size() try: recorded_events_queue, hooked = keyboard._recording keyboard.unhook(hooked) keyboard.unhook_all_hotkeys() except: pass try: keyboard.add_hotkey('Esc+q', self.endProgram, suppress=True) keyboard.start_recording() # Don't put anythiing below this line except: recorded_events_queue, hooked = keyboard._recording try: keyboard.unhook(hooked) print("unhooked") except: print("unable to call keyboard.unhook") pass self.stop_event_recording(exceptionFlag=True) self.MAIN_PROCESS_RUNNING_FLAG = True # variables related to frameExtractor self.frameExtractorStopped = False self.frameExtractorDfIndexSeen = 0 Thread(target=self.frameExtractor, args=(), daemon=True).start() print("completed init")
def record(): width = pyautogui.size()[0] height = pyautogui.size()[1] base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) mouse_events = [] #a mouse.hook(mouse_events.append) keyboard.start_recording() time.sleep(.2) #we move to arbitrary position and press a harmless key so the keyboard and mouse events start recording at the same time. pyautogui.moveTo(width / 2, height / 2) #move mouse to middle of screen pyautogui.press('left') keyboard.wait("`") #press this key to stop recording mouse.unhook(mouse_events.append) keyboard_events = keyboard.stop_recording() print(base_dir) pickle.dump(mouse_events, open(base_dir + r'/events/mouse.p', 'wb')) pickle.dump(keyboard_events, open(base_dir + r'/events/keyboard.p', 'wb'))
def get_update(self): elapsed = time.time() - self.start if elapsed < 10: kb.start_recording() time.sleep(0.08) events = kb.stop_recording() if len(events) > 1: if events[0].name == "up": self.y += 1 if events[0].name == "down": self.y += -1 if events[0].name == "right": self.x += 1 if events[0].name == "left": self.x -= 1 self.ax.clear() self.U, self.V = np.meshgrid(self.X + self.x, self.Y + self.y) self.ax.quiver(self.X, self.Y, self.U, self.V) self.fig.canvas.draw() else: self.terminate() return True
def listen(exit_condition): """ Main function to call, will implement a listener and return these events Should return raw dictionary with no parsing having occured :param exit_condition: Key, or list of key events, to stop the listener :return: List of time ordered keyboard events """ # Collect events until released # TODO use the passed exit condition start_time = time.clock() keyboard.start_recording() while True: if keyboard.is_pressed('esc'): recorded_keys = keyboard.stop_recording() break elif time.clock() - 30 > start_time: recorded_keys = keyboard.stop_recording() break return recorded_keys
def key_press_handler(self, key): if keyboard.is_modifier(key.scan_code): self.modifier |= MODIFIER[key.scan_code] self.key_hold = SCAN_CODES_HID_USAGEID_MAPPING[key.scan_code] if self.key_hold != self.macro_key: self.bt.send_report( modifier=self.modifier, code=(self.key_hold, 0x00, 0x00, 0x00, 0x00, 0x00) ) # replaying, press macro again to stop if self.replaying: if self.key_hold == self.macro_key: self.replaying = False else: if self.recording: # macro: stop record if self.key_hold == self.macro_key: try: # the first 2 elements is F1 down, F1 up self.replay_buf = keyboard.stop_recording()[2:] except ValueError: # if not keyboard.start_recording() pass finally: self.recording = False else: # F6: assign macro key if self.pre_key == 0x3f: self.macro_key = self.key_hold # F7: start record, prevent nested recording elif self.key_hold == 0x40: keyboard.start_recording() self.recording = True # macro: play the record elif self.key_hold == self.macro_key: self.replaying = True self.pre_key = self.key_hold
from graphics import * import keyboard import time """windowSize = 500 mainWin = GraphWin("Snake", windowSize, windowSize) a = Rectangle(Point(200,200),Point(300,300)) a.draw(mainWin) mainWin.getMouse() # Pause to view result mainWin.close() # Close window when done""" #recorded = keyboard.record(until='esc') #for a in recorded: # print(a,a.name,"\n") print("Starting:\n") keyboard.start_recording(recorded_events_queue=None) time.sleep(2) a = keyboard.stop_recording() for e in a: print(e.name,type(e.name))
def run(self): dir_path = os.path.dirname(os.path.realpath(__file__)) print(dir_path) keyboard.hook(self.__key_on) mouse.hook(self.__mouse_on) keyboard.start_recording() win32api.keybd_event( 160, 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0) ev_list = keyboard.stop_recording() if not ev_list and os.path.isfile(dir_path + r"\pywinauto_recorder.exe"): print("Couldn't set keyboard hooks. Trying once again...\n") time.sleep(0.5) os.system(dir_path + r"\pywinauto_recorder.exe --no_splash_screen") sys.exit(1) self.hicon = oaam.load_png(dir_path + r'\copy_clipboard.png', 64, 64) self.hicon_light_on = oaam.load_png(dir_path + r'\light_on.png', 40, 40) self.hicon_light_off = oaam.load_png(dir_path + r'\light_off.png', 40, 40) unique_candidate = None elements = [] i = 0 previous_wrapper_path = None unique_wrapper_path = None strategies = [ Strategy.unique_path, Strategy.array_2D, Strategy.array_1D ] i_strategy = 0 while self.mode != "Quit": try: self.main_overlay.clear_all() self.info_overlay.clear_all() x, y = win32api.GetCursorPos() wrapper = self.desktop.from_point(x, y) if wrapper is None: continue r = wrapper.rectangle() self.main_overlay.add(geometry=oaam.Shape.rectangle, x=x, y=r.top + r.height() + 20, width=300, height=25, thickness=1, color=(0, 0, 0), brush=oaam.Brush.solid, brush_color=(254, 25, 255)) self.info_overlay.add(x=x + 5, y=r.top + r.height() + 21, width=300, height=25, text="Name: " + wrapper.element_info.name, font_size=16, text_color=(0, 0, 0), color=(254, 255, 255), geometry=oaam.Shape.rectangle, thickness=0) self.main_overlay.add(geometry=oaam.Shape.rectangle, x=x, y=r.top + r.height() + 20 + 25 * (2 - 1), width=300, height=25, thickness=1, color=(0, 0, 0), brush=oaam.Brush.solid, brush_color=(254, 25, 255)) self.info_overlay.add(x=x + 5, y=r.top + r.height() + 21 + 25 * (2 - 1), width=300, height=25, text="Type:" + wrapper.element_info.control_type, font_size=16, text_color=(0, 0, 0), color=(254, 255, 255), geometry=oaam.Shape.rectangle, thickness=0) has_value = getattr(wrapper, "get_value", None) if callable(has_value): self.main_overlay.add(geometry=oaam.Shape.rectangle, x=x, y=r.top + r.height() + 20 + 25 * (3 - 1), width=300, height=25, thickness=1, color=(0, 0, 0), brush=oaam.Brush.solid, brush_color=(254, 25, 255)) self.info_overlay.add(x=x + 5, y=r.top + r.height() + 21 + 25 * (3 - 1), width=300, height=25, text="Value: " + wrapper.get_value(), font_size=16, text_color=(0, 0, 0), color=(254, 255, 255), geometry=oaam.Shape.rectangle, thickness=0) wrapper_path = get_wrapper_path(wrapper) if not wrapper_path: continue if wrapper_path == previous_wrapper_path: if (unique_wrapper_path is None) or (strategies[i_strategy] == Strategy.array_2D): i_strategy = i_strategy + 1 if i_strategy >= len(strategies): i_strategy = len(strategies) - 1 else: i_strategy = 0 previous_wrapper_path = wrapper_path entry_list = get_entry_list(wrapper_path) unique_candidate, elements = find_element( self.desktop, entry_list, window_candidates=[]) strategy = strategies[i_strategy] unique_wrapper_path = None if strategy == Strategy.unique_path: if unique_candidate is not None: unique_wrapper_path = get_wrapper_path( unique_candidate) r = wrapper.rectangle() self.main_overlay.add(geometry=oaam.Shape.rectangle, x=r.left, y=r.top, width=r.width(), height=r.height(), thickness=1, color=(0, 128, 0), brush=oaam.Brush.solid, brush_color=(0, 255, 0)) else: for e in elements: r = e.rectangle() self.main_overlay.add( geometry=oaam.Shape.rectangle, x=r.left, y=r.top, width=r.width(), height=r.height(), thickness=1, color=(0, 128, 0), brush=oaam.Brush.solid, brush_color=(255, 0, 0)) if strategy == Strategy.array_1D and elements: unique_array_1d = self.__find_unique_element_array_1d( wrapper.rectangle(), elements) if unique_array_1d is not None: unique_wrapper_path = wrapper_path + unique_array_1d else: strategy = Strategy.array_2D if strategy == Strategy.array_2D and elements: unique_array_2d = self.__find_unique_element_array_2d( wrapper.rectangle(), elements) if unique_array_2d is not None: unique_wrapper_path = wrapper_path + unique_array_2d if unique_wrapper_path is not None: self.last_element_event = ElementEvent( strategy, wrapper.rectangle(), unique_wrapper_path) if self.event_list and unique_wrapper_path is not None: self.event_list.append(self.last_element_event) if self.mode == 'Record': overlay_add_record_icon(self.main_overlay, 10, 10) elif self.mode == 'Pause': overlay_add_pause_icon(self.main_overlay, 10, 10) elif self.mode == 'Stop': self.main_overlay.clear_all() overlay_add_stop_icon(self.main_overlay, 10, 10) self.main_overlay.refresh() while self.mode == 'Stop': time.sleep(1.0) overlay_add_progress_icon(self.main_overlay, i, 60, 10) overlay_add_search_mode_icon(self.main_overlay, self.hicon_light_on, 110, 10) i = i + 1 self.main_overlay.refresh() self.info_overlay.refresh() time.sleep( 0.005 ) # main_overlay.clear_all() doit attendre la fin de main_overlay.refresh() except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() print( repr( traceback.format_exception(exc_type, exc_value, exc_traceback))) self.main_overlay.clear_all() self.main_overlay.refresh() if self.event_list: self.stop_recording() mouse.unhook_all() keyboard.unhook_all() print("Run end")
def start_log(): keyboard.start_recording() sleep(180) RemoteControl.stop_log()
def __init__(self, sp): # Make queue to receive kb events self.in_q = queue.Queue() keyboard.start_recording(self.in_q) self.news_sp = sp
def main(): keyboard.start_recording() loadJSON() t_watcher = Thread(target=JSON_modify_watcher) t_watcher.start()
def record(self): keyboard.start_recording() time.sleep(4) recorded = keyboard.stop_recording() if recorded[0].name == 'right': print('right')
def test_start_stop_recording(self): keyboard.start_recording() self.do(d_a+u_a) self.assertEqual(keyboard.stop_recording(), d_a+u_a)
import keyboard import time keyboard.start_recording() time.sleep(10) events = keyboard.stop_recording() keyboard.replay(events)
def start_keystrokes(self): #start recording the keystrokes keyboard.start_recording()
import keyboard import grpc from trash import keyboard_pb2_grpc, keyboard_pb2 import queue keyboard.start_recording() keyboard.stop_recording() b = 'a' KeyboardEvent = keyboard.KeyboardEvent down = keyboard.KEY_DOWN up = keyboard.KEY_UP class IterQueue(queue.Queue): def __iter__(self): while True: yield self.get() def run(): print('keyboard started') channel = grpc.insecure_channel('localhost:5678') stub = keyboard_pb2_grpc.KeyboardStub(channel) # response = stub.sayHello(mouse_pb2.EventString(event='ff')); # print(response); for e in stub.GetKeyboard(keyboard_pb2.KeyStroke(key=b)): # print(e.key) # print(e.key) x = e.key.split()[0] # print(x)
def test_start_stop_recording(self): keyboard.start_recording() self.do(d_a + u_a) self.assertEqual(keyboard.stop_recording(), d_a + u_a)
while input("Press any key to Start --> \n\n"): op = int( input("Select any option \n1.Start Keylogger \n2.Get Keylogs \n3.Exit" ).strip()) if op == 1: #Start Key Logger print("Starting Key Logger In 3 Sec \n Press ESC to Stop Keylogger\n") for var in range(1, 4): # Loading ... print(var, end="-", flush=True) sleep(1) else: print("\nStarted .....") # Key logger started sleep(2) kb.press_and_release("cmd + down") sleep(0.1) kb.press_and_release("cmd + down") kb.start_recording() while True: if kb.is_pressed("esc"): # Press ESC To Stop Key logger data = kb.stop_recording() # key logger Stoped break fp = open("log.db", "wb") pk.dump(data, fp) # writing keylogs in log.db file fp.close() break elif op == 2: # Get Keylogs print("Opening Wordpad please wait ....") fp = open("log.db", "rb") data = pk.load(fp) # Loading Keylogs from log.db file fp.close() os.system("write.exe") sleep(2)