# XrInput

Class · extends [`EventHandler`](https://api.playcanvas.com/engine/classes/EventHandler.md) · category: XR

Source: https://github.com/playcanvas/engine/blob/dfcc50fbbfba2388843041a875ec0ef5d1a586c5/src/framework/xr/xr-input.js#L20

Provides access to input sources for WebXR.

Input sources represent:

- hand held controllers - and their optional capabilities: gamepad and vibration
- hands - with their individual joints
- transient sources - such as touch screen taps and voice commands

## Accessors

### inputSources

```ts
get inputSources(): XrInputSource[]
```

List of active [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) instances.

## Events

### EVENT_ADD

```ts
static EVENT_ADD: string = 'add'
```

Fired when a new [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) is added to the list. The handler is passed the
[XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) that has been added.

**Example**

```ts
app.xr.input.on('add', (inputSource) => {
    // new input source is added
});
```

### EVENT_REMOVE

```ts
static EVENT_REMOVE: string = 'remove'
```

Fired when an [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) is removed from the list. The handler is passed the
[XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) that has been removed.

**Example**

```ts
app.xr.input.on('remove', (inputSource) => {
    // input source is removed
});
```

### EVENT_SELECT

```ts
static EVENT_SELECT: string = 'select'
```

Fired when [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) has triggered primary action. This could be pressing a
trigger button, or touching a screen. The handler is passed the [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) that
triggered the `select` event and the XRInputSourceEvent event from the WebXR API.

**Example**

```ts
const ray = new Ray();
app.xr.input.on('select', (inputSource, evt) => {
    ray.set(inputSource.getOrigin(), inputSource.getDirection());
    if (obj.intersectsRay(ray)) {
        // selected an object with input source
    }
});
```

### EVENT_SELECTEND

```ts
static EVENT_SELECTEND: string = 'selectend'
```

Fired when [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) has ended triggering primary action. The handler is passed
the [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) that triggered the `selectend` event and the XRInputSourceEvent
event from the WebXR API.

**Example**

```ts
app.xr.input.on('selectend', (inputSource, evt) => {
    console.log('Select ended');
});
```

### EVENT_SELECTSTART

```ts
static EVENT_SELECTSTART: string = 'selectstart'
```

Fired when [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) has started to trigger primary action. The handler is
passed the [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) that triggered the `selectstart` event and the
XRInputSourceEvent event from the WebXR API.

**Example**

```ts
app.xr.input.on('selectstart', (inputSource, evt) => {
    console.log('Select started');
});
```

### EVENT_SQUEEZE

```ts
static EVENT_SQUEEZE: string = 'squeeze'
```

Fired when [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) has triggered squeeze action. This is associated with
"grabbing" action on the controllers. The handler is passed the [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) that
triggered the `squeeze` event and the XRInputSourceEvent event from the WebXR API.

**Example**

```ts
app.xr.input.on('squeeze', (inputSource, evt) => {
    console.log('Squeeze');
});
```

### EVENT_SQUEEZEEND

```ts
static EVENT_SQUEEZEEND: string = 'squeezeend'
```

Fired when [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) has ended triggering squeeze action. The handler is passed
the [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) that triggered the `squeezeend` event and the XRInputSourceEvent
event from the WebXR API.

**Example**

```ts
app.xr.input.on('squeezeend', (inputSource, evt) => {
    console.log('Squeeze ended');
});
```

### EVENT_SQUEEZESTART

```ts
static EVENT_SQUEEZESTART: string = 'squeezestart'
```

Fired when [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) has started to trigger squeeze action. The handler is
passed the [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) that triggered the `squeezestart` event and the
XRInputSourceEvent event from the WebXR API.

**Example**

```ts
app.xr.input.on('squeezestart', (inputSource, evt) => {
    if (obj.containsPoint(inputSource.getPosition())) {
        // grabbed an object
    }
});
```

## Inherited from [EventHandler](https://api.playcanvas.com/engine/classes/EventHandler.md)

- `fire(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): EventHandler`
- `hasEvent(name: string): boolean`
- `off(name?: string, callback?: HandleEventCallback, scope?: any): EventHandler`
- `on(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
- `once(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
