On the keyboard hook acquisition

On the keyboard hook acquisition

pyHook Import 
Import PythonCOM 

class E (): 
    keyIsPressed # = False hold the keyboard is depressed. . 
    def onKeyDow (self, event): # key presses 
        if self.keyIsPressed: # If persistent hold the keyboard is no longer to print text 
            return True 
        Print (STR (event.key) + 'pressed IS') 
        self.keyIsPressed = true # press first 
        if (event.Key == 'E') : # If e is pressed and returns false print Efalse pressed the keyboard is intercepted e does not perform 
            print (str (event.Key) + 'FALSE') 
            return False 
        return True 

    DEF onKeyU (Self, Event): # keyboard lift 
        self.keyIsPressed = False 
        t_e = event.key 
        Print (STR (t_e) + 'lift IS') 
        IF (t_e == 'E '): e is not performed raised #
         Print # (STR (t_e) + 'FALSE')
            False return 
        return True 

IF the __name__ == '__main__': 
    mykbmanager = E () 
    hookmanager pyHook.HookManager = () # Create a hook handle 
    hookmanager.KeyDown = mykbmanager.onKeyDow 
    hookmanager.KeyUp = mykbmanager.onKeyU 
    hookmanager.HookKeyboard () # Start hook 
    pythoncom.PumpMessages (10000) # is used to sustain a hook message acquisition cycle
 

  

Guess you like

Origin www.cnblogs.com/moshuixiong/p/11334970.html