Skip to main content

GameControllerModule

Class

Provides access to game controller input on Spectacles.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
1 platform note
  • SnapchatNot supported — Available on SPECS only
  • SPECSFully supported
    • Experimental API; it may change or be removed.
  • Camera Kit WebNot supported — Available on SPECS only
  • Camera Kit MobileNot supported — Available on SPECS only

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported. Experimental API; it may change or be removed

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not supported — Available on SPECS only.

Since Lens Scripting v373Experimental

Provides access to game controller input on Spectacles. Import this module to enable game controller support in your Lens.

Use createController() to open a session and subscribe to input events from connected Bluetooth game controllers. The session provides controller discovery, input events, and haptic feedback (rumble). Subscribe to events via the session's event properties (e.g. onButtonEvent.add(...)). Multiple controller sessions may be active simultaneously.

Index

Example

//@input Asset.GameControllerModule gameControllerModule
var provider = script.gameControllerModule.createController();
provider.onControllerConnected.add(function(event) {
print("Connected: " + event.controller.name + " (type: " + event.controller.type + ")");
});
provider.onButtonEvent.add(function(event) {
if (event.button === GameControllerModule.Button.South
&& event.eventType === GameControllerModule.ButtonEventType.Pressed) {
var options = new GameControllerModule.RumbleOptions();
options.controllerId = event.controllerId;
options.lowFrequencyIntensity = 0.5;
options.highFrequencyIntensity = 0.3;
options.durationSec = 0.2;
provider.rumble(options);
}
});

Extends

Properties

name

name: string

Experimental

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Experimental

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

createController()

createController(): GameControllerSession

ExperimentalSPECS

Creates a new game controller session and subscribes to the platform service. Returns a GameControllerSession whose event properties can be used to subscribe to controller lifecycle and input events.

Returns

GameControllerSession

Since

Lens Scripting Version 373


getTypeName()

static getTypeName(): TypeName<GameControllerModule>

ExperimentalSPECS

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<GameControllerModule>

Since

Lens Scripting Version 373

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Experimental

Returns the name of this object's type.

Returns

string

Inherited from

Asset.getTypeName


isOfType()

isOfType(type): boolean

Experimental

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Asset.isOfType


isSame()

isSame(other): boolean

Experimental

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Asset.isSame

Nested types

Enumerations

EnumerationDescription
ButtonCommon gamepad button identifiers. Face buttons use positional names (compass directions when looking at the right-hand button diamond) so they are layout-neutral across controller families. Use ControllerInfo.type to map these to platform-appropriate labels.
ButtonEventTypeWhether a button changed to pressed or released.
ControllerCapabilityOptional capabilities a controller may support. These are individual flags that can be combined (bitmask). Use ControllerInfo.hasCapability for convenience.
ControllerTypeController family as reported by the device. Useful for displaying correct button labels. Third-party controllers commonly identify as one of the first-party types.
SideWhich side of the controller a thumbstick or trigger belongs to.
TouchStateState of a single touch point on the controller touchpad.

Classes

ClassDescription
AnalogStickInputEventFired when a thumbstick's axis values change.
AnalogTriggerInputEventFired when a trigger's analog axis value changes.
ButtonInputEventFired when a button is pressed or released on a connected controller.
ControllerConnectedEventFired when a new game controller is connected.
ControllerDisconnectedEventFired when a game controller is disconnected.
ControllerInfoMetadata describing a connected game controller.
MotionInputEventFired when motion sensor data (gyroscope, accelerometer) is received. Only available on controllers that support motion.
RumbleOptionsOptions for a haptic feedback (rumble) request. Uses a dual-motor model: a heavy low-frequency motor and a light high-frequency motor.
TouchInfoA single touch point on the controller touchpad.
TouchpadInputEventFired when touchpad input is received. Only available on controllers with a touchpad.