From 6d6e8beefd956272e8741a4edd1ef86166259376 Mon Sep 17 00:00:00 2001 From: alters Date: Mon, 16 Nov 2020 11:50:21 -0500 Subject: [PATCH 1/2] send_keyboard --- Documentation/api/command_api.md | 33 +++++++++++++++ Documentation/api/output_data.md | 18 ++++++++ Python/setup.py | 2 +- Python/tdw/FBOutput/Keyboard.py | 73 ++++++++++++++++++++++++++++++++ Python/tdw/output_data.py | 26 +++++++++++- Python/tdw/version.py | 2 +- 6 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 Python/tdw/FBOutput/Keyboard.py diff --git a/Documentation/api/command_api.md b/Documentation/api/command_api.md index e0e6f8544..3ca67758b 100644 --- a/Documentation/api/command_api.md +++ b/Documentation/api/command_api.md @@ -454,6 +454,7 @@ | [`send_environments`](#send_environments) | Receive data about the environment(s) in the scene. Only send this command after initializing the environment in one of two ways: 1) create_exterior_walls, 2) load_streamed_scene | | [`send_humanoids`](#send_humanoids) | Send transform (position, rotation, etc.) data for humanoids in the scene. | | [`send_junk`](#send_junk) | Send junk data. | +| [`send_keyboard`](#send_keyboard) | Request keyboard input data. | | [`send_version`](#send_version) | Receive data about the build version. | | [`send_vr_rig`](#send_vr_rig) | Send data for a VR Rig currently in the scene. | @@ -5486,6 +5487,38 @@ Options for when to send data. *** +## **`send_keyboard`** + +Request keyboard input data. + +- **Sends data**: This command instructs the build to send output data. + + - **Type:** [`Keyboard`](output_data.md#Keyboard) + +```python +{"$type": "send_keyboard"} +``` + +```python +{"$type": "send_keyboard", "frequency": "once"} +``` + +| Parameter | Type | Description | Default | +| --- | --- | --- | --- | +| `"frequency"` | Frequency | The frequency at which data is sent. | "once" | + +#### Frequency + +Options for when to send data. + +| Value | Description | +| --- | --- | +| `"once"` | Send the data for this frame only. | +| `"always"` | Send the data every frame. | +| `"never"` | Never send the data. | + +*** + ## **`send_version`** Receive data about the build version. diff --git a/Documentation/api/output_data.md b/Documentation/api/output_data.md index 0a0b729ca..600eb21c2 100644 --- a/Documentation/api/output_data.md +++ b/Documentation/api/output_data.md @@ -70,6 +70,7 @@ Objects in arrays can't be directly accessed (this is due to how the backend cod | [Images](#Images) | The images and associated metadata that were captured by an avatar. | `imag` | | [ImageSensors](#ImageSensors) | The names of each ImageSensor component attached to an avatar, and whether they are enabled. | `imse` | | [IsOnNavMesh](#IsOnNavMesh) | Data regarding whether a position is on the NavMesh. Invoked by first sending the command `send_is_on_nav_mesh`. | `isnm` | +| [Keyboard](#Keyboard) | Keyboard input. Note that in order to receive keyboard input, the build must be the focused window and running on the same computer as the keyboard. | `keyb` | | [LogMessage](#LogMessage) | A log message sent by the build. | `logm` | | [Meshes](#Meshes) | Mesh data from readable objects. | `mesh` | | [NavMeshPath](#NavMeshPath) | A path on the scene's NavMesh. | `path` | @@ -423,6 +424,23 @@ Data regarding whether a position is on the NavMesh. Invoked by first sending th | `get_position()` | If is_on == False, this is (inf, inf inf). If is_on == True, this is a valid position on the NavMesh. | `Tuple[float, float, float]` | | `get_is_on()` | True if `position` is a valid position on the NavMesh. | `bool` | +## Keyboard + +`k = Keyboard(byte_array)` + +**Identifier:** `keyb` + +Keyboard input. Note that in order to receive keyboard input, the build must be the focused window and running on the same computer as the keyboard. + +| Function | Description | Return type | +| --- | --- | --- | +| `get_num_pressed()` | The number of pressed. | `int` | +| `get_pressed(index)` | Keys that were first pressed between the previous frame and this frame. | `str` | +| `get_num_held()` | The number of held. | `int` | +| `get_held(index)` | Keys that are being pressed down. | `str` | +| `get_num_released()` | The number of released. | `int` | +| `get_released()` | Keys that were released between the previous frame and this frame. | `str` | + ## LogMessage `l = LogMessage(byte_array)` diff --git a/Python/setup.py b/Python/setup.py index d1f97eb50..aa55d1f53 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages from pathlib import Path -__version__ = "1.7.8.0" +__version__ = "1.7.9.0" readme_path = Path('../README.md') if readme_path.exists(): long_description = readme_path.read_text(encoding='utf-8') diff --git a/Python/tdw/FBOutput/Keyboard.py b/Python/tdw/FBOutput/Keyboard.py new file mode 100644 index 000000000..c11db6ec2 --- /dev/null +++ b/Python/tdw/FBOutput/Keyboard.py @@ -0,0 +1,73 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: FBOutput + +import tdw.flatbuffers + +class Keyboard(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsKeyboard(cls, buf, offset): + n = tdw.flatbuffers.encode.Get(tdw.flatbuffers.packer.uoffset, buf, offset) + x = Keyboard() + x.Init(buf, n + offset) + return x + + # Keyboard + def Init(self, buf, pos): + self._tab = tdw.flatbuffers.table.Table(buf, pos) + + # Keyboard + def Pressed(self, j): + o = tdw.flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + tdw.flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # Keyboard + def PressedLength(self): + o = tdw.flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Keyboard + def Held(self, j): + o = tdw.flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + tdw.flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # Keyboard + def HeldLength(self): + o = tdw.flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Keyboard + def Released(self, j): + o = tdw.flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.String(a + tdw.flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return "" + + # Keyboard + def ReleasedLength(self): + o = tdw.flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + +def KeyboardStart(builder): builder.StartObject(3) +def KeyboardAddPressed(builder, pressed): builder.PrependUOffsetTRelativeSlot(0, tdw.flatbuffers.number_types.UOffsetTFlags.py_type(pressed), 0) +def KeyboardStartPressedVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def KeyboardAddHeld(builder, held): builder.PrependUOffsetTRelativeSlot(1, tdw.flatbuffers.number_types.UOffsetTFlags.py_type(held), 0) +def KeyboardStartHeldVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def KeyboardAddReleased(builder, released): builder.PrependUOffsetTRelativeSlot(2, tdw.flatbuffers.number_types.UOffsetTFlags.py_type(released), 0) +def KeyboardStartReleasedVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def KeyboardEnd(builder): return builder.EndObject() diff --git a/Python/tdw/output_data.py b/Python/tdw/output_data.py index f955427a6..ef60e7012 100644 --- a/Python/tdw/output_data.py +++ b/Python/tdw/output_data.py @@ -31,8 +31,9 @@ from tdw.FBOutput import Raycast as Ray from tdw.FBOutput import Overlap as Over from tdw.FBOutput import NavMeshPath as Path +from tdw.FBOutput import Keyboard as Key import numpy as np -from typing import Tuple, Optional +from typing import Tuple, Optional, List class OutputDataUndefinedError(Exception): @@ -795,3 +796,26 @@ def get_path(self) -> np.array: def get_id(self) -> int: return self.data.Id() + + +class Keyboard(OutputData): + def get_data(self) -> Key.Keyboard: + return Key.Keyboard.GetRootAsKeyboard(self.bytes, 0) + + def get_num_pressed(self) -> int: + return self.data.PressedLength() + + def get_pressed(self, index: int) -> str: + return self.data.Pressed(index).decode('utf-8') + + def get_num_held(self) -> int: + return self.data.HeldLength() + + def get_held(self, index: int) -> str: + return self.data.Held(index).decode('utf-8') + + def get_num_released(self) -> int: + return self.data.ReleasedLength() + + def get_released(self) -> str: + return self.data.Released(index).decode('utf-8') diff --git a/Python/tdw/version.py b/Python/tdw/version.py index daa6b8866..34a31cc2a 100644 --- a/Python/tdw/version.py +++ b/Python/tdw/version.py @@ -1 +1 @@ -__version__ = "1.7.8" +__version__ = "1.7.9" From fa119bf56f9283411e9a736f19431fd1d6dca874 Mon Sep 17 00:00:00 2001 From: alters Date: Mon, 16 Nov 2020 11:53:33 -0500 Subject: [PATCH 2/2] changelog --- Documentation/Changelog.md | 18 ++++++++++++++++++ README.md | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Documentation/Changelog.md b/Documentation/Changelog.md index b02c261ef..ba70fd329 100644 --- a/Documentation/Changelog.md +++ b/Documentation/Changelog.md @@ -4,6 +4,24 @@ To upgrade from TDW v1.6 to v1.7, read [this guide](Documentation/v1.6_to_v1.7). +## v1.7.9 + +### Command API + +#### New Commands + +| Command | Description | +| --------------- | ---------------------------- | +| `send_keyboard` | Request keyboard input data. | + +### Output Data + +#### New Output Data + +| Output Data | Description | +| ----------- | -------------------- | +| `Keyboard` | Keyboard input data. | + ## v1.7.8 ### Python diff --git a/README.md b/README.md index db4c89d67..ca753b365 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ ### [C# Code](https://github.com/threedworld-mit/tdw/blob/master/Documentation/contributions/c_sharp_sources.md) -### [License](https://github.com/threedworld-mit/tdw/blob/LICENSE.txt) +### [License](https://github.com/threedworld-mit/tdw/blob/master/LICENSE.txt) ### [How to upgrade from TDW v1.6 to v1.7](https://github.com/threedworld-mit/tdw/blob/master/Documentation/v1.6_to_v1.7.md)