GameControllerModule
ClassProvides access to game controller input on Spectacles.
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- 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
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
Properties
Methods
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
uniqueIdentifier
readonlyuniqueIdentifier:string
Experimental
Since
Lens Scripting Version 176
Inherited from
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
Since
Lens Scripting Version 373
getTypeName()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Experimental
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Experimental
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
Nested types
Enumerations
| Enumeration | Description |
|---|---|
| Button | Common 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. |
| ButtonEventType | Whether a button changed to pressed or released. |
| ControllerCapability | Optional capabilities a controller may support. These are individual flags that can be combined (bitmask). Use ControllerInfo.hasCapability for convenience. |
| ControllerType | Controller family as reported by the device. Useful for displaying correct button labels. Third-party controllers commonly identify as one of the first-party types. |
| Side | Which side of the controller a thumbstick or trigger belongs to. |
| TouchState | State of a single touch point on the controller touchpad. |
Classes
| Class | Description |
|---|---|
| AnalogStickInputEvent | Fired when a thumbstick's axis values change. |
| AnalogTriggerInputEvent | Fired when a trigger's analog axis value changes. |
| ButtonInputEvent | Fired when a button is pressed or released on a connected controller. |
| ControllerConnectedEvent | Fired when a new game controller is connected. |
| ControllerDisconnectedEvent | Fired when a game controller is disconnected. |
| ControllerInfo | Metadata describing a connected game controller. |
| MotionInputEvent | Fired when motion sensor data (gyroscope, accelerometer) is received. Only available on controllers that support motion. |
| RumbleOptions | Options for a haptic feedback (rumble) request. Uses a dual-motor model: a heavy low-frequency motor and a light high-frequency motor. |
| TouchInfo | A single touch point on the controller touchpad. |
| TouchpadInputEvent | Fired when touchpad input is received. Only available on controllers with a touchpad. |