-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Use this program as a wrapper to all for more concurrent use of PyGame events and it allows for multiple events of the same type to be polled from different parts of the code.
Pygame is needed obviously and typing allows for type hints in IDEs and code editors - so you can see what types of variables should be passed in.
This creates all the variables needed for the system to work, e.g.
name_of_var = events_sync()
This allows for all the events to be processed, and appropriate actions to be taken, e.g.
name_of_var()
This allows for key phrases - a unique string-based identifier - to be mapped to Pygame key, e.g.
name_of_var.config('down', pygame.K_s)
This allows for the python function to be assigned to events, even keyboard events with specific keys! Arguments can be passed into these functions, e.g.
Keyboard event with key
name_of_var.listen(pygame.KEYDOWN, my_func, pygame.K_s)
Keyboard event with key phrase
name_of_var.listen(pygame.KEYDOWN, my_func, 'down')
Event with args
name_of_var.listen(pygame.QUIT, my_quit_func, None, x, y, z, a=b, c=d)
Important None
must be put in place of the usual keyboard key if args and kwargs are used.
If a keyphrase is passed in that is never defined using name_of_var.config()
an error will be raised looking like this:
Traceback (most recent call last):
File "c:\path_to_file\name_of_file.py", line 1, in <module>
e.listen(pygame.KEYDOWN, t, 'hello')
File "c:\path_to_file\name_of_file.py", line 2, in listen
raise Exception(
Exception: The provided key phrase: xyz, was not defined or set, did you use *.config('xyz', *)?
This error can just be fixed using name_of_var.config('xyz', pygame.K_a)
This allows for events to be latched onto for later action, e.g.
name_of_var.latch(pygame.QUIT)
This allows events that have been latched onto be retrieved in order of [least recent -> most recent], so least recent first, e.g.
x = name_of_var.retrieve(pygame.QUIT)