August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
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:
Warning!
You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.
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, 05 Jun 2009 at 03:01:38 UTC/GMT