I have a python graphical application that runs in a terminal and accepts keyboard input using the pynput module. The issue I am having is that pynput accepts input all the time, even when the terminal running the application is not in focus by my window manager. This makes it difficult to shift focus to another task without accidentally typing into the application.
Ideally, I would like to be able to either:
- Have pynput reject input when the terminal is not in focus
OR
- Have some way of determining when the application gains/loses focus (so I can simulate #1 myself)
I have searched the pynput documentation, but I cannot find a solution. Any advice on how to accomplish this is appreciated. I am using Linux.