npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vr-input-source

v0.0.1

Published

vr-input-source tracks all positionally-tracked gamepads, and exposes them in an API similar to the `XRInputSource` defined in the upcoming WebXR API.

Downloads

8

Readme

vr-input-source

vr-input-source tracks all positionally-tracked gamepads, and exposes them in an API similar to the XRInputSource defined in the upcoming WebXR API.

The package performs a few key tasks related to using VR input sources. It keeps track of all connected gamepads that report their physical position, and fires events when their buttons are pressed or released. When multiple gamepads are used simultaneously, typically two-handed controllers like Oculus Touch, it tracks which one was most recently used. This allows developers to use that controller as the device that controls the cursor, a behavior commonly seen on VR platforms.

Button Events

The Web Gamepad API relies on polling to get gamepad data, and does not fire events like keyboard or mouse inputs. This requires some code to run on each rendered frame, inspect gamepad state, and determine which buttons changed since the last frame. vr-input-source performs this action for all tracked gamepads, and will fire the following events:

Primary Button Events

Primary buttons are those that perform a selection action, and vary from controller to controller. Due to the wide range of input devices used for VR, it's recommended that developers build interfaces around a single select action, rather than relying on the presence of many buttons. How a button is determined to be primary or secondary is described in a later section.

  • selectstart - Triggered when one of the gamepad's primary buttons is pressed down. Similar to mousedown.
  • selectend - Triggered when one of the gamepad's primary buttons is released, or the gamepad is disconnected while some buttons are pressed. Similar to mouseup.
  • select - Triggered when one of the gamepad's primary buttons is pressed down, then released. Similar to click.

Alternative Button Events

Generic button-press events also exist to track when any button, primary or otherwise, is pressed or released.

  • pressstart - Triggered when any of the gamepad's buttons is pressed down. Similar to mousedown.
  • pressend - Triggered when any of the gamepad's buttons is released, or the gamepad is disconnected while some buttons are pressed. Similar to mouseup.
  • press - Triggered when any of the gamepad's buttons is pressed down, then released. Similar to click.

Capacitive Button Events

Some controllers have capacitive buttons or trackpads

  • touchstart - Triggered when the user's finger touches a capacitive button.
  • touchend - Triggered when a user's finger stops touching a capacitive button.

Primary vs Secondary

Some gamepads have a single button (Daydream); others have a button and a trigger (Oculus Go); others have many different buttons (Oculus Touch, Vive Wand, Windows MR Motion Controllers). There is rarely a correlation between the reported ordering of the buttons and their intended action. vr-input-source is aware of popular gamepads, and maps their primary actions to the select events. For example, it maps both the A button and main trigger on Oculus Touch as primary actions. For unrecognized gamepads, every button is considered primary. This is to future-proof applications against new input hardware; otherwise, developers would need to upgrade older apps to add mappings for new devices.

The list of recognized gamepad mappings is found in WellKnownGamepads.js, and can be updated to support new input types.

Controller Events

The top-level VRInputSource class also fires events related to changes in input devices.

  • inputsourceschange - Triggered when the set of connected gamepads with pose changes. This could either be the result of a connection or a disconnection.
  • activesourcechange - Triggered when the Active Input Source changes. The active source is the gamepad that was most recently used. This can be used by the application to change which gamepad draws the cursor.