Bonjours,
Je travaille sous windows avec python 2.7. Mon objectif est d'écrire dans un fichier txt (mot.txt) le mot qui est en train d'être saisi (uniquement le mot)
J'ai donc tapé ce code ci-dessous
Mais visiblement la ligne f.write(syntaxe) pose problème... et je ne comprends pas pourquoi.
Merci pour votre aide
Gabriel
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 import pyHook import win32api import pythoncom import sys def OnKeyboardEvent(touche): f=open(r'c:\mot.txt','r') syntaxe=f.read() f.close() f=open(r'c:\mot.txt','w') if touche.Ascii==32: print syntaxe f.write('') elif touche.Ascii!=0: syntaxe+=chr(touche.Ascii) f.write(syntaxe) f.close() return True f=open(r'c:\mot.txt','w') f.write('') f.close() # create the hook mananger hm = pyHook.HookManager() # register two callbacks #hm.MouseAllButtonsDown = OnMouseEvent hm.KeyDown=OnKeyboardEvent # hook into the mouse and keyboard events #hm.HookMouse() hm.HookKeyboard() #if __name__ == '__main__': # import pythoncom # pythoncom.PumpMessages() pythoncom.PumpMessages()
Partager