DOM. MouseManager

Manages the mouse input.

Constructor

new MouseManager(preventDefaultopt)

Parameters:
NameTypeAttributesDefaultDescription
preventDefaultBoolean<optional>
false

Prevent the Default behavior on press right button

Examples
const mouse = new DOM.MouseManager();
const { x, y } = mouse;
console.log(x, y);
import { DOM } from "201flaviosilva-labs";
const { MouseManager, MouseManagerInstance, MouseButton, } = DOM
const beepDiv = document.getElementById("MyDiv");
const mouse = new MouseManager(true);
setInterval(() => console.log(mouse.getPosition(beepDiv)), 1000);
MouseManagerInstance.events.on("buttonDown-left", () => console.log("down -> left"));
MouseManagerInstance.events.on("buttonDown-right", () => console.log("up -> right"));

Members

(static) this.events

A event system to get on a key is pressed

Examples
DOM.MouseManagerInstance.events.on("buttonDown-left", () => console.log("down -> left"));
DOM.MouseManagerInstance.events.on("buttonUp-left", () => console.log("up -> left"));

(static) this.isDown

All pressed buttons will appear here

Examples
console.log(DOM.MouseManager.isPressed["left"]);
console.log(DOM.MouseManager.isPressed[DOM.MouseManager.getNameByKeyCode(0)]);

Methods

(static) MouseManager#getButtonKeyByName(buttonName) → {number}

Returns the code of the button by the button name.

Parameters:
NameTypeDescription
buttonNamestring

The name of the button

Returns:

The button code

Type: 
number
Example
console.log(DOM.MouseManager.getButtonCodeByName("left")); // 0

(static) MouseManager#getNameByButtonCode(buttonCode) → {string}

Returns the name of the button by the button code.

Parameters:
NameTypeDescription
buttonCodenumber

The button code

Returns:

The name of the button

Type: 
string
Example
console.log(DOM.MouseManager.getNameByButtonCode(1)); // "middle"

(static) MouseManager#getPosition(DOMElementopt) → {Object}

Returns the mouse position to the given DOM Element

If no given Element is passed returns de mouse in the window localization

Parameters:
NameTypeAttributesDescription
DOMElementHTMLElement<optional>

The DOM Element to check the mouse position

Returns:

The current mouse position {x, y}

Type: 
Object
Example
const { x, y } = DOM.MouseManager.getPosition();
const { x, y } = DOM.MouseManager.getPosition(document.getElementById("myDiv"));

(static) MouseManager#isButtonDown(button) → {boolean}

Returns if the button is pressed.

Parameters:
NameTypeDescription
buttonstring | number

The button name or code

Returns:

True if the button is pressed

Type: 
boolean
Example
DOM.MouseManager.isButtonPressed("left") // True

(static) MouseManager#isButtonDownByButtonCode(button) → {boolean}

Returns if the button is pressed by the button code.

Parameters:
NameTypeDescription
buttonstring | number

The button code

Returns:

True if the button is pressed

Type: 
boolean
Example
DOM.MouseManager.isButtonDownByName(2) // True

(static) MouseManager#isButtonDownByName(button) → {boolean}

Returns if the button is pressed by the button name.

Parameters:
NameTypeDescription
buttonstring | number

The button name

Returns:

True if the button is pressed

Type: 
boolean
Example
DOM.MouseManager.isButtonDownByName("left") // True