Skip to content

Capturing Inputs

Introduction

We tried to capture input from a HID (Human Interaction Device), like a keyboard, mouse, or any other kind of remote.

Research

When looking into ways to capture the input we tried to listen for key press events, but this turned out to be harder then expected. There are various libraries that can be used to achive this goal. When trying to implement a few of them they did not work as expected. The documentation for most of them seems to be out of date (incorrect for the latest React versions).

Solution

We’ve decided to use the (https://github.com/kevinejohn/react-native-keyevent) library, the documentation was out of date as well, but there were some issues where the correct information was provided.

To test the ability to capture keystrokes from a keyboard we implemented it on the Android Platform with a path to also get it to work on IOS if required in the future.

How it works

The library requires some native code to pass along the key press events, this will then get handled by the library and converted to React code. The logic that happens when we press a specific key is also created on the React side (not native) so it can technically work on every platform that is supported by React Native.


Last update: April 20, 2023