I am trying to detect global keypresses in python. (I am a complete noob in Python). My problem is that pyHook recognizes my key events but it doesn't let me type anymore. If I try to type something into the opened selenium webdriver (see code), nothing happens, except for the keyid being printed.
Here is my 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()
Maybe someone can tell me how to fix it?
greetings