Je travaille actuellement avec une bibliothèque en Python qui enregistre toutes les entrées de l'utilisateur. Le code source peut être trouvé ici: https://github.com/JeffHoogland/pyxhook/blob/master/pyxhook.pyConfusion sur les classes Python dans le code source Pyxhook
J'ai regardé la source pendant un certain temps et ne peux pas comprendre comment cela fonctionne réellement. J'ai tracé la fonction processevents(self, reply)
dans toute la source et je ne comprends pas d'où vient le vairble event
. Les lignes exactes sont:
def processevents(self, reply):
if reply.category != record.FromServer:
return
if reply.client_swapped:
print("* received swapped protocol data, cowardly ignored")
return
try:
# Get int value, python2.
intval = ord(reply.data[0])
except TypeError:
# Already bytes/ints, python3.
intval = reply.data[0]
if (not reply.data) or (intval < 2):
# not an event
return
data = reply.data
while len(data):
event, data = rq.EventField(None).parse_binary_value(
data,
self.record_dpy.display,
None,
None
)
if event.type == X.KeyPress:
hookevent = self.keypressevent(event)
self.KeyDown(hookevent)
elif event.type == X.KeyRelease:
hookevent = self.keyreleaseevent(event)
self.KeyUp(hookevent)
elif event.type == X.ButtonPress:
hookevent = self.buttonpressevent(event)
self.MouseAllButtonsDown(hookevent)
elif event.type == X.ButtonRelease:
hookevent = self.buttonreleaseevent(event)
self.MouseAllButtonsUp(hookevent)
elif event.type == X.MotionNotify:
# use mouse moves to record mouse position, since press and
# release events do not give mouse position info
# (event.root_x and event.root_y have bogus info).
hookevent = self.mousemoveevent(event)
self.MouseMovement(hookevent)
# print("processing events...", event.type)
La fonction rq.EventField (Aucun) de .parse_binary_value() est en retournant un objet événement qui a taper comme un attribut au sein it.It renvoie également data.So , pour chaque pression de touche ou bouton, un objet événement est créé – bigbounty
Je ne suis pas familier avec cette fonction, d'où vient-elle? – Astrum
Je risque de deviner que ces événements sont émis par le système d'exploitation, et n'ont rien à voir avec Python. Ils sont capturés et énumérés par l'interface Xlib [python] (https://github.com/python-xlib). –