Using pynput on macOS


While working on my personal project Darth-Vader-RPi , I used the Python package pynput for monitoring the keyboard as to simulate push buttons on a Raspberry Pi. However, some keyboard keys were not detected on macOS without running the script with sudo (after adding PYTHONPATH to etc/sudoers). 

The keyboard keys that didn't need sudo were the following:
  • alt keys
  • cmd keys
  • ctrl keys
  • media buttons for play, pause, volume up/down/mute
  • shift keys
The other keyboard keys (all the alphanumeric and some special keys such as backspace and right) required the Python script to run with sudo.

The pynput documentation explains the modifications you should apply to your application if you want to make it run on Linux, macOS, or Windows.


Image credit: "Apple Key" by Antijingoist is licensed under CC BY-NC-ND 2.0

Comments

Popular posts from this blog

Deactivate conda's base environment on startup

Draw arrows with GIMP plugins

Product review: SMONET wireless security camera system