# MouseEvent

Class · category: Input Devices

Source: https://github.com/playcanvas/engine/blob/f059dc005842f76e052cdf44d8370c8c7ec475ac/src/platform/input/mouse-event.js#L27

The MouseEvent object is passed into all event handlers registered on the [Mouse](https://api.playcanvas.com/engine/classes/Mouse.md). The
events are:

- [Mouse.EVENT_MOUSEDOWN](https://api.playcanvas.com/engine/classes/Mouse.md#event_mousedown)
- [Mouse.EVENT_MOUSEUP](https://api.playcanvas.com/engine/classes/Mouse.md#event_mouseup)
- [Mouse.EVENT_MOUSEMOVE](https://api.playcanvas.com/engine/classes/Mouse.md#event_mousemove)
- [Mouse.EVENT_MOUSEWHEEL](https://api.playcanvas.com/engine/classes/Mouse.md#event_mousewheel)

## Constructors

### constructor

```ts
new MouseEvent(mouse: Mouse, event: MouseEvent | WheelEvent)
```

Create a new MouseEvent instance.

**Parameters**

- `mouse` ([`Mouse`](https://api.playcanvas.com/engine/classes/Mouse.md)): The Mouse device that is firing this event.
- `event` (`MouseEvent | WheelEvent`): The original browser event that fired.

## Properties

### altKey

```ts
altKey: boolean = false
```

True if the alt key was pressed when this event was fired.

### button

```ts
button: number = MOUSEBUTTON_NONE
```

The mouse button associated with this event. Can be:

- [MOUSEBUTTON_LEFT](https://api.playcanvas.com/engine/variables/MOUSEBUTTON_LEFT.md)
- [MOUSEBUTTON_MIDDLE](https://api.playcanvas.com/engine/variables/MOUSEBUTTON_MIDDLE.md)
- [MOUSEBUTTON_RIGHT](https://api.playcanvas.com/engine/variables/MOUSEBUTTON_RIGHT.md)

### buttons

```ts
buttons: boolean[]
```

The pressed state of all mouse buttons at the time this event was fired. A 3-element
array of booleans for left, middle and right buttons respectively.

### ctrlKey

```ts
ctrlKey: boolean = false
```

True if the ctrl key was pressed when this event was fired.

### dx

```ts
dx: number = 0
```

The change in x coordinate since the last mouse movement event. When the pointer is not
locked, this is zero until an unlocked movement establishes a position after creation,
detachment, focus loss, movement outside the target or pointer-locked movement. Under
pointer lock, this uses the browser's relative movement delta.

### dy

```ts
dy: number = 0
```

The change in y coordinate since the last mouse movement event. When the pointer is not
locked, this is zero until an unlocked movement establishes a position after creation,
detachment, focus loss, movement outside the target or pointer-locked movement. Under
pointer lock, this uses the browser's relative movement delta.

### element

```ts
element: Element
```

The element that the mouse was fired from.

### event

```ts
event: MouseEvent | WheelEvent
```

The original browser event.

### metaKey

```ts
metaKey: boolean = false
```

True if the meta key was pressed when this event was fired.

### shiftKey

```ts
shiftKey: boolean = false
```

True if the shift key was pressed when this event was fired.

### wheelDelta

```ts
wheelDelta: number = 0
```

A value representing the amount the mouse wheel has moved, only valid for
[Mouse.EVENT_MOUSEWHEEL](https://api.playcanvas.com/engine/classes/Mouse.md#event_mousewheel) events.

### x

```ts
x: number = 0
```

The x coordinate of the mouse pointer relative to the element [Mouse](https://api.playcanvas.com/engine/classes/Mouse.md) is attached to.

### y

```ts
y: number = 0
```

The y coordinate of the mouse pointer relative to the element [Mouse](https://api.playcanvas.com/engine/classes/Mouse.md) is attached to.
