システム全体で押したキー (キーロガー) を記録し、タイピングの習慣に関する情報を自宅に呼び出す Python スクリプトを作成しています。私はPythonが初めてで、このアプリケーションを使用して学習しています。私はpython-3.xとwindows 8を使用しています
完全なソース コードは、 https://github.com/funvill/QSMonitor/blob/master/monitor.pyにあります。
このスニペットを使用すると、システム全体ですべてのキープレスを記録できます。問題は、[ctrl]+[c] で別のウィンドウに何かをコピーすると、Python コードがクラッシュすることです。
再現する手順
- monitor.py スクリプトを実行する
- 別のウィンドウ (notepad.exe) で、いくつかの文字 (abcd) を入力します。
- メモ帳で文字を強調表示し、[ctrl] を押しながら [c] を押します。
経験者:
Windows のエラー メッセージがポップアップし、python.exe が機能を停止したため、再起動する必要があることが通知されます。コマンド ウィンドウに Python エラー メッセージは表示されませんでした。
def OnKeyboardEvent(event):
global keyDatabase
global keyLoggerCount
keyLoggerCount += 1
# http://code.activestate.com/recipes/553270-using-pyhook-to-block-windows-keys/
print ('MessageName:',event.MessageName )
print ('Message:',event.Message)
print ('Time:',event.Time)
print ('Window:',event.Window)
print ('WindowName:',event.WindowName)
print ('Ascii:', event.Ascii, chr(event.Ascii) )
print ('Key:', event.Key)
print ('KeyID:', event.KeyID)
print ('ScanCode:', event.ScanCode)
print ('Extended:', event.Extended)
print ('Injected:', event.Injected)
print ('Alt', event.Alt)
print ('Transition', event.Transition)
print ('---')
# check to see if this key has ever been pressed before
# if it has not then add it and set its start value to zero.
if event.Key not in keyDatabase:
keyDatabase[ event.Key ] = 0 ;
# Incurment the key value
keyDatabase[ event.Key ] += 1 ;
return True
# When the user presses a key down anywhere on their system
# the hook manager will call OnKeyboardEvent function.
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
while True :
pythoncom.PumpWaitingMessages()
私の質問は:
- コピーと過去のクラッシュの原因は何ですか?