I am using pynput to record keystrokes via Listener on OS X Mojave. I am using Pycharm as my IDE for running the code.
I was not able to get it to work using the same example from the pynput site.
from pynput.keyboard import Listener as key_listener
class recorder:
def on_press(self, key):
print(key)
def on_release(self, key):
print(key)
if __name__ == "__main__":
testme = recorder()
with key_listener(on_press=testme.on_press, on_release=testme.on_release) as listener:
listener.join()
I did step through it and I get no errors (unless I put the with
statement in a function, instead of in the main, but that's a known issue with threading in Mojave, from what I can tell after searching for that error), but everything stops at the .join()
statement, and I get nothing printed when I press and release a key on my keyboard.
This is probably a bit late, but the answer is to go into:
Security & Privacy
Privacy
tab +
Hold down CMD
+ SHIFT
+ .
(so that you can see hidden
files/folders) /usr/local/bin
or wherever you have Python installedokay
.That should do it.
Note
If you try to run your app via the terminal, you will need to add the terminal.app to the list of allowed apps, as done above for Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With