This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-05-19 14:00:36

WingsGames
Scratcher
Registered: 2011-02-21
Posts: 500+

Python Question

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!"


Are you an aspiring home decorator? If so, please answer my question!

Offline

 

#2 2012-05-19 16:44:26

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: Python Question

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

 

#3 2012-05-19 16:58:14

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: Python Question

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!  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

Board footer