How do you get Python to sense when a certain key is pressed?
For instance, when the k key is pressed, it would print "You've pressed K!"
Offline
WingsGames wrote:
How do you get Python to sense when a certain key is pressed?
For instance, when the k key is pressed, it would print "You've pressed K!"
it heavily depends on what you're doing. if you're doing shell scripting, you should better look here, if you're doing some kind of GUI, for example wx or tkinter, just search google for 'keyboard events GUIlib python'
if you need help binding the method, just ask!
Offline
As roijac points out, it depends what you're using.
If you want to get basic text input from a terminal, you can just use the built-in raw_input() function.
If you're trying to do something more like a game — to check if an arrow key is pressed, for example — you might want to check out something like pygame.
Hope that helps!
Offline