Skip to content

Commit

Permalink
Merge pull request #106 from threedworld-mit/send_keyboard
Browse files Browse the repository at this point in the history
send_keyboard
  • Loading branch information
alters-mit authored Nov 16, 2020
2 parents cfe9392 + fa119bf commit 2aa18e4
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 4 deletions.
18 changes: 18 additions & 0 deletions Documentation/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions Documentation/api/command_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand Down Expand Up @@ -5486,6 +5487,38 @@ Options for when to send data.

***

## **`send_keyboard`**

Request keyboard input data.

- <font style="color:green">**Sends data**: This command instructs the build to send output data.</font>

- <font style="color:green">**Type:** [`Keyboard`](output_data.md#Keyboard)</font>

```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.
Expand Down
18 changes: 18 additions & 0 deletions Documentation/api/output_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down Expand Up @@ -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)`
Expand Down
2 changes: 1 addition & 1 deletion Python/setup.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
73 changes: 73 additions & 0 deletions Python/tdw/FBOutput/Keyboard.py
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 25 additions & 1 deletion Python/tdw/output_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')
2 changes: 1 addition & 1 deletion Python/tdw/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.7.8"
__version__ = "1.7.9"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2aa18e4

Please sign in to comment.