Witam, napisałem taki oto program:
import time, datetime, os, sys
import subprocess, base64,platform
import pythoncom, pyHook, win32api, win32gui, win32con
def OnKeyboardEvent(event):
print ("MessageName:", event.MessageName)
print ("Message:", event.Message)
print ("Time:", event.Time)
print ("Window:", event.Window)
print ("WindowName:", event.WindowName)
print ("Ascii:", 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 ("------")
return True
def log():
state = True
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
while True:
log()
który po wciśnięciu klawisza z klawiatury pokazuje informacje na jego temat. Program działa gdy są uruchomione inne programy, np. gdy wpisujemy coś w pasku URL i działa poprawnie ale gdy np.chce coś napisać w notatniku to się crashuje i wywala taki błąd:
TypeError: KeyboardSwitch() missing 8 required positional arguments: 'msg', 'vk_code', 'scan_code', 'ascii', 'flags', 'time', 'hwnd', and 'win_name'
Logi z konsoli:
MessageName: key down
Message: 256
Time: 2181421
Window: 459886
WindowName: test
Ascii: 116
Key: T
KeyID: 84
ScanCode: 20
Extended: 0
Injected: 0
Alt: 0
Transition: 0
------
TypeError: KeyboardSwitch() missing 8 required positional arguments: 'msg', 'vk_code', 'scan_code', 'ascii', 'flags', 'time', 'hwnd', and 'win_name'
Sprawdziłem w internecie problem i błąd może wynikać z wersji PyHooka gdy ja używam python3.
Odpowiedzią jest https://github.com/Answeror/pyhook_py3k ale tutaj mam kolejny problem, nigdy nie programowałem w pythonie, nie wiem jak mógłbym "zupdateować" pyhooka, instrukcja jest tylko do MSVC9. Ja używam tylko SublimeText3.