# InputSource

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

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/extras/input/input.js#L153

The base class for all input devices. An input source is an [InputFrame](https://api.playcanvas.com/engine/classes/InputFrame.md) that fills its own
deltas from DOM events or device polling once [attach](https://api.playcanvas.com/engine/classes/InputSource.md#attach) is given an element, and stops on
[detach](https://api.playcanvas.com/engine/classes/InputSource.md#detach). Call [InputFrame#read](https://api.playcanvas.com/engine/classes/InputFrame.md#read) once per frame to take the accumulated deltas. The
built-in sources are [KeyboardMouseSource](https://api.playcanvas.com/engine/classes/KeyboardMouseSource.md), [GamepadSource](https://api.playcanvas.com/engine/classes/GamepadSource.md),
[MultiTouchSource](https://api.playcanvas.com/engine/classes/MultiTouchSource.md), [SingleGestureSource](https://api.playcanvas.com/engine/classes/SingleGestureSource.md) and [DualGestureSource](https://api.playcanvas.com/engine/classes/DualGestureSource.md); subclass
this to add another device.

**template** The shape of the input source.

## Properties

### _element

```ts
protected _element: HTMLElement | null = null
```

## Methods

### attach

```ts
attach(element: HTMLElement): void
```

**Parameters**

- `element` (`HTMLElement`): The element.

### destroy

```ts
destroy(): void
```

### detach

```ts
detach(): void
```

### fire

```ts
fire(event: string, ...args: any[]): void
```

Fires an event with the given name and arguments.

**Parameters**

- `event` (`string`): The event name to fire.
- `args` (`any[]`): The arguments to pass to the event listeners.

### off

```ts
off(event: string, callback: HandleEventCallback): void
```

Removes an event listener for the specified event.

**Parameters**

- `event` (`string`): The event name to stop listening for.
- `callback` ([`HandleEventCallback`](https://api.playcanvas.com/engine/types/HandleEventCallback.md)): The callback function to remove.

### on

```ts
on(event: string, callback: HandleEventCallback): void
```

Adds an event listener for the specified event.

**Parameters**

- `event` (`string`): The event name to listen for.
- `callback` ([`HandleEventCallback`](https://api.playcanvas.com/engine/types/HandleEventCallback.md)): The callback function to execute when the event is
  triggered.

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

- `new InputSource<T extends Record<string, number[]>>(data: T)`
- `deltas: { [K in string | number | symbol]: InputDelta }`
- `read(): { [K in string | number | symbol]: number[] }`
