In the keyboard library, there are functions that let you run certain bits of code when it detects, for example, that you click "esc", but is there a way to instead make it so when you click any key it returns what key you pressed in a variable?
The only way to do this that I've come up with so far is if I have to loop through all the keys to test if they are being pressed with the function keyboard.is_pressed()
, although this seems slow and I don't know if there is a list of all the possible key presses. I'm also using pygame if that has a similar function to what I'm looking for.
I am not trying to run things depending on what key is pressed, for example making a sprite move depending what arrow key you press, I'm trying to simply store what key is being pressed in a dictionary (with the dictionary key being the keyboard key pressed, and the value being the current state of the screen), so that you can restore/rollback to the state of the screen when they use the key they used to save it. I can't simply take a screenshot and then display it, because there is more data behind that, for example the data of the sprites on screen