0
所以我正在写一个记录击键的程序,它很好用,直到我点击离开程序框。当我点击柯塔娜像一个浏览器,并开始打字,它记录了几笔,然后完全停止。它也没有抛出任何错误,所以我不知道如何调试它。为什么pythoncom.pumpmessages()停止工作?
def run(self):
hm = pyHook.HookManager()
hm.KeyDown = self.OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
def OnKeyboardEvent(self,event):
ch=chr(event.Ascii)
#print [ch]
if ch in '\x00\x08':
val='/*'+event.Key+'*/'
if (val!=self.prev or ch=='\x08') and 'Capital' not in val:
print val,
self.writetofile(str(val))
data=shelve.open('loggerinfo')
data['strokes']=data['strokes'].append(val)
data.close()
self.prev=val
else:
self.prev=ch
char=None
if ch=='\r':
char='/*return*/'
elif ch=='\t':
char='/*tab*/'
else:
char=ch
if char!=None:
print char,
self.writetofile(str(char))
data=shelve.open('loggerinfo')
data['strokes']=data['strokes'].append(char)
data.close()
return True
我不知道是什么问题,因为它不会引发错误。