2017-07-29 8 views
1

J'essaie de détecter les presses globales en python. (Je suis un Noob complet en Python). Mon problème est que pyHook reconnaît mes événements clés, mais il ne me laisse plus taper. Si j'essaye de taper quelque chose dans le webdriver de sélénium ouvert (voir le code), rien ne se passe, excepté le keyid en cours d'impression.pyHook ne me laisse pas taper

Voici mon code:

import pyHook, pythoncom, sys, win32api 
from colorama import Fore, init 
from selenium import webdriver 

add_key = 187 #keyID for "+" key 
commands = ["start", "quit", "save", "help"] 
urls = [] 
driver = webdriver.Chrome() 

def OnKeyboardEvent(event): 
    print(event.KeyID) 
    if event.KeyID == add_key: 
     print("add key pressed") 
     urls.append(driver.current_url) 
    return 0 

def PrintHelpMessage(): 
    # write help message 
    MainLoop() 

def MainLoop(): 
    print(Fore.GREEN + "type commands for more help.") 

    usr_input = input() 
    if usr_input == "commands": 
     print(Fore.GREEN + "available commands: start, quit, save, help") 
     command_input = input() 
     if command_input in commands: 
      if command_input == "start": 
       hook_manager = pyHook.HookManager() 
       hook_manager.KeyDown = OnKeyboardEvent 
       hook_manager.HookKeyboard() 
       pythoncom.PumpMessages() 
      elif command_input == "quit": 
       sys.exit(0) 
      elif command_input == "save": 
       # implement save function 
       print("Save function implemented soon") 
      elif command_input == "help": 
       PrintHelpMessage() 


init(autoreset = True) # init colorama -> makes it possible to use colored text in terminal 
print(Fore.RED + "---easy playlist manager---") 
driver.get("http://youtube.com") 
MainLoop() 

Peut-être que quelqu'un peut me dire comment résoudre ce problème?

salutations

Répondre

0

Vous retournez 0 dans OnKeyboardEvent, de sorte que le cas du clavier ne sont pas transmises à d'autres gestionnaires ou la fenêtre elle-même. Si vous ne souhaitez pas filtrer l'événement, vous devez renvoyer True. Pour plus d'informations, voir Event Filtering dans la documentation.