recently I have made a CLI program using Python and it uses a library called keyboard
. The program is working very well but have something that hurts me...
For any reason when I start it in Windows works normally, but on Linux (probably on MacOS too) gives a error of permission. What i know about this library is that it captures the keys even when the terminal windows is inactive, maybe the Linux think this dangerous and ask for super user. I particularly don't care to get the user "keypressers" even when the terminal window is inactive (Only in active terminal is great for me)
then I looked for some libraries similar this one, but for any reason don't work pretty similar. the keyboard
library has a function called is_pressed()
that returns a boolean value based if a specific key is pressed, for example: if is_pressed('space')
, but I didn't find a alternative library that have a similar function.
Assuming this is for a game, you might want to take a look at the pygame
framework. It has an eventloop specifically for this kind of purpose. Docs here.