此代码工作正常,但是当我按下最小化或关闭按钮时,程序窗口会冻结一段时间。原因可能是在 HookMouse 中,没有它,窗口最小化和关闭正常。为什么?
import wx
import pyHook
class myFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'My Frame')
self.tc=wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize,
wx.TE_MULTILINE|wx.TE_NOHIDESEL|wx.TE_READONLY)
self.hm = pyHook.HookManager()
self.hm.KeyDown = self.OnKeyboardEvent
self.hm.HookKeyboard()
self.hm.MouseLeftDown=self.OnKeyboardEvent
self.hm.HookMouse()
wx.EVT_CLOSE(self, self.OnClose)
def OnGetAO(self, event):
self.tc.Value+=event.MessageName+"\n"
def OnKeyboardEvent(self, event):
wx.CallAfter(self.OnGetAO, event)
def OnClose(self, event):
del self.hm
self.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp(0)
frame = myFrame()
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()