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()
def run(self): print('Running...') hm = HookManager() hm.HookKeyboard() hm.KeyDown = self.handle_keydown hm.KeyUp = self.handle_keyup hm.start()
def main(): onKeyPress = Constructor() keyboard = HookManager() keyboard.KeyDown = onKeyPress keyboard.KeyUp = onKeyPress keyboard.HookKeyboard() keyboard.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()
def writeEvent( e, K, M ): 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 )
#!/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()
# 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()
global current_buffer _key = event.Key if _key in ignore_keys: return if allowed_characters.find(_key) != -1: current_buffer = current_buffer + _key else: current_buffer = current_buffer.lower() if current_buffer in words_dictionary: sendmessage("{0} `{1}`?".format(funnymessages[randint(0,len(funnymessages))], current_buffer)) current_buffer = "" #Keyboard Hookup settings hm = HookManager() hm.HookKeyboard() hm.KeyUp = Handle_Keyboard_Event def WriteScreen(message): print "[{0}]:\t{1}".format(str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), message) def Handle_User(): global current_buffer cmd = str(raw_input()).strip().lower() current_buffer = "" #empty up buffer if cmd == "close": StopService() return False else: args = cmd.split(' ') if args[0] == "add": new_word = args[1]
#!/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()
index = index + 1 else: current_buffer = current_buffer.lower() if current_buffer in words_dictionary: sendmessage("{0} `{1}`?".format( funnymessages[randint(0, len(funnymessages) - 1)], current_buffer)) current_buffer = "" index = 0 #Keyboard Hookup settings hm = HookManager() hm.HookKeyboard() hm.KeyUp = Handle_Keyboard_Event def WriteScreen(message): print "[{0}]:\t{1}".format( str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), message) def Handle_User(): global current_buffer cmd = str(raw_input()).strip().lower() current_buffer = "" #empty up buffer if cmd == "close": StopService() return False else: