A component that registers with a Pygame Display service component to receive key-up and key-down events from Pygame. You can set up this component to send out different messages from different outboxes depending on what key is pressed.
Capture keypresses in pygame for numbers 1,2,3 and letters a,b,c:
fom pygame.locals import * Graphline( output = ConsoleEchoer(), keys = KeyEvent( key_events={ K_1 : (1,"numbers"), K_2 : (2,"numbers"), K_3 : (3,"numbers"), K_a : ("A", "letters"), K_b : ("B", "letters"), K_c : ("C", "letters"), }, outboxes={ "numbers" : "numbers between 1 and 3", "letters" : "letters between A and C", } ), linkages = { ("keys","numbers"):("output","inbox"), ("keys","letters"):("output","inbox") } ).run()
The symbols K_1, K_2, etc are keycodes defined in defined in pygame.locals.
This component requests a zero sized display surface from the Pygame Display service component and registers to receive events from pygame.
Whenever a KEYDOWN event is received, the pygame keycode is looked up in the mapping you specified. If it is there, then the specified message is sent out of the specified outbox.
In addition, if the allKeys flag was set to True during initialisation, then any KEYDOWN or KEYUP event will result in a ("DOWN",keycode) or ("UP",keycode) message being sent to the "allkeys" outbox.
If you have specified a message to send for a particular key, then both that message and the 'all-keys' message will be sent when the KEYDOWN event occurs.
If this component receives a shutdownMicroprocess or producerFinished message on its "control" inbox, then this will be forwarded out of its "signal" outbox and the component will then terminate.
KeyEvent([allkeys][,key_events][,outboxes]) -> new KeyEvent component.
Component that sends out messages in response to pygame keypress events.
Keyword arguments:
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Main loop.
Generator. yields 1 until data is ready on the named inbox.
Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!
Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.
-- Automatic documentation generator, 19 Oct 2008 at 14:29:09 UTC/GMT