pywinhook crashes tkinter window

66 Views Asked by At

I create a new thread and run the hook, but when I try to do something with the mouse or keyboard on the window, it does not respond and crashes, I've been trying for a long time, but I couldn't find a solution.

import threading

import pyWinhook as pyHook
import pythoncom
import tkinter as tk

def OnKeyboardEvent(event):
    return True

def OnMouseEvent(event):
    print("+")
    return True

def hook():
    hm = pyHook.HookManager()

    hm.MouseAllButtons = OnMouseEvent
    hm.KeyAll = OnKeyboardEvent

    hm.HookMouse()
    hm.HookKeyboard()
    pythoncom.PumpMessages()


root = tk.Tk()
threading.Thread(target=hook).start()
root.mainloop()
0

There are 0 best solutions below