# KeyboardMouseSource

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/keyboard-mouse-source.js#L70

Keyboard and mouse input source class. Attached to an element, it accumulates `key` deltas for
the keys listed in [keyCode](https://api.playcanvas.com/engine/classes/KeyboardMouseSource.md#keycode), `button` deltas for the mouse buttons, `mouse` deltas for
pointer movement and `wheel` deltas for the scroll wheel. Pass `pointerLock: true` to use
pointer lock for mouse movement.

## Constructors

### constructor

```ts
new KeyboardMouseSource(options?: object)
```

**Parameters**

- `options` (`object`, optional, default `{}`): The options.
    - `options.pointerLock` (`boolean`, optional, default `false`): Whether to enable pointer lock.

## Properties

### _button

```ts
_button: number[]
```

### keyCode

```ts
static readonly keyCode: { 0: 26; 1: 27; 2: 28; 3: 29; 4: 30; 5: 31; 6: 32; 7: 33; 8: 34; 9: 35; A: 0; B: 1; C: 2; CTRL: 42; D: 3; DOWN: 37; E: 4; F: 5; G: 6; H: 7; I: 8; J: 9; K: 10; L: 11; LEFT: 38; M: 12; N: 13; O: 14; P: 15; Q: 16; R: 17; RIGHT: 39; S: 18; SHIFT: 41; SPACE: 40; T: 19; U: 20; UP: 36; V: 21; W: 22; X: 23; Y: 24; Z: 25 } = KEY_CODES
```

The key codes for the keyboard keys.

**Properties**

- `0` (`26`, optional, default `26`)
- `1` (`27`, optional, default `27`)
- `2` (`28`, optional, default `28`)
- `3` (`29`, optional, default `29`)
- `4` (`30`, optional, default `30`)
- `5` (`31`, optional, default `31`)
- `6` (`32`, optional, default `32`)
- `7` (`33`, optional, default `33`)
- `8` (`34`, optional, default `34`)
- `9` (`35`, optional, default `35`)
- `A` (`0`, optional, default `0`)
- `B` (`1`, optional, default `1`)
- `C` (`2`, optional, default `2`)
- `CTRL` (`42`, optional, default `42`)
- `D` (`3`, optional, default `3`)
- `DOWN` (`37`, optional, default `37`)
- `E` (`4`, optional, default `4`)
- `F` (`5`, optional, default `5`)
- `G` (`6`, optional, default `6`)
- `H` (`7`, optional, default `7`)
- `I` (`8`, optional, default `8`)
- `J` (`9`, optional, default `9`)
- `K` (`10`, optional, default `10`)
- `L` (`11`, optional, default `11`)
- `LEFT` (`38`, optional, default `38`)
- `M` (`12`, optional, default `12`)
- `N` (`13`, optional, default `13`)
- `O` (`14`, optional, default `14`)
- `P` (`15`, optional, default `15`)
- `Q` (`16`, optional, default `16`)
- `R` (`17`, optional, default `17`)
- `RIGHT` (`39`, optional, default `39`)
- `S` (`18`, optional, default `18`)
- `SHIFT` (`41`, optional, default `41`)
- `SPACE` (`40`, optional, default `40`)
- `T` (`19`, optional, default `19`)
- `U` (`20`, optional, default `20`)
- `UP` (`36`, optional, default `36`)
- `V` (`21`, optional, default `21`)
- `W` (`22`, optional, default `22`)
- `X` (`23`, optional, default `23`)
- `Y` (`24`, optional, default `24`)
- `Z` (`25`, optional, default `25`)

## Methods

### attach

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

**Parameters**

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

### detach

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

### read

```ts
read(): { button: number[]; key: number[]; mouse: number[]; wheel: number[] }
```

**Returns** `{ button: number[]; key: number[]; mouse: number[]; wheel: number[] }`

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

- `protected _element: HTMLElement | null = null`
- `deltas: { button: InputDelta; key: InputDelta; mouse: InputDelta; wheel: InputDelta }`
- `destroy(): void`
- `fire(event: string, ...args: any[]): void`
- `off(event: string, callback: HandleEventCallback): void`
- `on(event: string, callback: HandleEventCallback): void`
