def update_keys(self, new_key_list=None):
"""
Populates our registry and other dicts with the new key-list given (may be an empty list).
:param Union[List,None] new_key_list: the new key list, where each item is the lower-case pygame keycode without the leading
`K_` e.g. `up` for pygame.K_UP; use None for clearing out the registry (no keys assigned)
"""
self.unregister_events()
self.keyboard_registry.clear()
self.descriptions.clear()
#OBSOLETE: self.desc_to_key.clear()
if new_key_list:
for desc in new_key_list:
key = getattr(pygame, "K_" + (desc.upper() if len(desc) > 1 else desc))
self.keyboard_registry[key] = False
self.descriptions[key] = desc
#OBSOLETE: self.desc_to_key[desc] = key
# signal that we might trigger the following events:
self.register_event("key_down." + desc, "key_up." + desc)
评论列表
文章目录