from tdw.add_ons.keyboard import Keyboard
Add keyboard controls to a TDW scene.
-
commands
These commands will be appended to the commands of the nextcommunicate()
call. -
initialized
If True, this module has been initialized.
__init__
Keyboard()
self.get_initialization_commands()
This function gets called exactly once per add-on. To re-initialize, set self.initialized = False
.
Returns: A list of commands that will initialize this add-on.
self.on_send(resp)
This is called within Controller.communicate(commands)
after commands are sent to the build and a response is received.
Use this function to send commands to the build on the next Controller.communicate(commands)
call, given the resp
response.
Any commands in the self.commands
list will be sent on the next Controller.communicate(commands)
call.
Parameter | Type | Default | Description |
---|---|---|---|
resp | List[bytes] | The response from the build. |
self.before_send(commands)
This is called within Controller.communicate(commands)
before sending commands to the build. By default, this function doesn't do anything.
Parameter | Type | Default | Description |
---|---|---|---|
commands | List[dict] | The commands that are about to be sent to the build. |
self.get_early_initialization_commands()
This function gets called exactly once per add-on. To re-initialize, set self.initialized = False
.
These commands are added to the list being sent on communicate()
before any other commands, including those added by the user and by other add-ons.
Usually, you shouldn't override this function. It is useful for a small number of add-ons, such as loading screens, which should initialize before anything else.
Returns: A list of commands that will initialize this add-on.
self.listen(key, commands)
self.listen(key, commands, function=None, events=None)
Listen for when a key is pressed and send commands.
Parameter | Type | Default | Description |
---|---|---|---|
key | str | The keyboard key. | |
commands | Union[dict, List[dict] | Commands to be sent when the key is pressed. | |
function | Callable | None | Function to invoke when the key is pressed. |
events | List[str] | None | Listen to these keyboard events for this key . Options: "press" , "hold" , "release" . If None, this defaults to ["press"] . |