Skip to content

HoloPlay.Buttons

Get access to the buttons on the Looking Glass device with HoloPlay.Buttons. Buttons extends from EventTarget, which lets you listen for button events through addEventListener().

Code example

const buttons = new HoloPlay.Buttons();
buttons.addEventListener('buttonPressed', (e) => {
  console.log(`Button pressed: ${e.detail.name}`);
});

Constructor

HoloPlay.Buttons()

Creates a new Buttons object, which fires events when the Looking Glass buttons are pressed.

Methods

.addEventListener(type : Number, listener : Function)

type - the type of event to listen for (e.g. buttonPressed, buttonDown, buttonUp).

listener - the function that gets called when the event is fired. The button name will be specified in e.detail.name (where e is passed to your listener function).

Sets up a function that will be called whenever the specified button event occurs.

Events

buttonPressed

Fires every frame while a Looking Glass button is held down.

buttonDown

Fires once when the Looking Glass button is first touched.

buttonUp

Fires once when the Looking Glass button is no longer pressed.

Additional info

BUTTON_NAMES

[square, left, right, circle]

All HoloPlay button events will specify their corresponding button as e.detail.name.