Skip to main content

Class: MouseHandler

input/mouse.MouseHandler

Handles mouse events for an {@link HTMLElement}.

Constructors

constructor

โ€ข new MouseHandler(element)

Parameters

NameType
elementHTMLElement

Defined in

src/input/mouse.ts:32

Properties

buttons

โ€ข Private buttons: Object = {}

Index signature

โ–ช [index: number]: boolean

Defined in

src/input/mouse.ts:29


element

โ€ข Readonly element: HTMLElement

Defined in

src/input/mouse.ts:22


listeners

โ€ข Private listeners: Object = {}

Index signature

โ–ช [index: number]: MouseCallback[]

Defined in

src/input/mouse.ts:30


position

โ€ข Private position: vec2

The mouse's current position within the element.

Defined in

src/input/mouse.ts:27

Methods

addListener

โ–ธ addListener(button, cb): void

Attaches a listener to a given mouse button that is called whenever the state of the button changes.

Parameters

NameTypeDescription
buttonMouseThe Mouse button to attach the listener to
cbMouseCallbackThe callback to execute on a mousedown/mouseup event

Returns

void

Defined in

src/input/mouse.ts:87


addListeners

โ–ธ Private addListeners(): void

Returns

void

Defined in

src/input/mouse.ts:37


getMousePos

โ–ธ getMousePos(): vec2

Gets the current mouse position within the element.

If the mouse has not yet entered the element then the position will be [0, 0].

Returns

vec2

The mouse position in pixels as a {@link vec2};

Defined in

src/input/mouse.ts:67


isPressed

โ–ธ isPressed(button?): boolean

Determines wether the given mouse button is pressed.

Parameters

NameTypeDefault valueDescription
buttonMouseMouse.LEFTThe Mouse button to check

Returns

boolean

Wether the given button is pressed or not

Defined in

src/input/mouse.ts:77


removeListener

โ–ธ removeListener(button, cb): void

Removes a listener from a given mouse button.

Parameters

NameTypeDescription
buttonMouseThe Mouse button the listener is attached to
cbMouseCallbackThe attached listener

Returns

void

Defined in

src/input/mouse.ts:101