# GamepadSource

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

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/extras/input/sources/gamepad-source.js#L33

Game pad input source class. Each [read](https://api.playcanvas.com/engine/classes/GamepadSource.md#read) polls the connected gamepads and yields
`buttons` deltas for the buttons listed in [buttonCode](https://api.playcanvas.com/engine/classes/GamepadSource.md#buttoncode), and `leftStick` and
`rightStick` deltas as `[x, y]`.

## Constructors

### constructor

```ts
new GamepadSource()
```

## Properties

### buttonCode

```ts
static readonly buttonCode: { A: 0; B: 1; LB: 4; LEFT_STICK: 10; LT: 6; RB: 5; RIGHT_STICK: 11; RT: 7; SELECT: 8; START: 9; X: 2; Y: 3 } = BUTTON_CODES
```

The button codes (based on Xbox controller layout).

**Properties**

- `A` (`0`, optional, default `0`)
- `B` (`1`, optional, default `1`)
- `LB` (`4`, optional, default `4`)
- `LEFT_STICK` (`10`, optional, default `10`)
- `LT` (`6`, optional, default `6`)
- `RB` (`5`, optional, default `5`)
- `RIGHT_STICK` (`11`, optional, default `11`)
- `RT` (`7`, optional, default `7`)
- `SELECT` (`8`, optional, default `8`)
- `START` (`9`, optional, default `9`)
- `X` (`2`, optional, default `2`)
- `Y` (`3`, optional, default `3`)

## Methods

### read

```ts
read(): { buttons: number[]; leftStick: number[]; rightStick: number[] }
```

**Returns** `{ buttons: number[]; leftStick: number[]; rightStick: number[] }`

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

- `protected _element: HTMLElement | null = null`
- `deltas: { buttons: InputDelta; leftStick: InputDelta; rightStick: InputDelta }`
- `attach(element: HTMLElement): void`
- `destroy(): void`
- `detach(): void`
- `fire(event: string, ...args: any[]): void`
- `off(event: string, callback: HandleEventCallback): void`
- `on(event: string, callback: HandleEventCallback): void`
