Constructor
new MouseManager(preventDefaultopt)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
preventDefault | Boolean | <optional> | false | Prevent the Default behavior on press right button |
- Source
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
- Source
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
- Source
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.
Name | Type | Description |
---|---|---|
buttonName | string | The name of the button |
- Source
The button code
- Type:
- number
console.log(DOM.MouseManager.getButtonCodeByName("left")); // 0
(static) MouseManager#getNameByButtonCode(buttonCode) → {string}
Returns the name of the button by the button code.
Name | Type | Description |
---|---|---|
buttonCode | number | The button code |
- Source
The name of the button
- Type:
- string
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
Name | Type | Attributes | Description |
---|---|---|---|
DOMElement | HTMLElement | <optional> | The DOM Element to check the mouse position |
- Source
The current mouse position {x, y}
- Type:
- Object
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.
Name | Type | Description |
---|---|---|
button | string | | The button name or code |
- Source
True if the button is pressed
- Type:
- boolean
DOM.MouseManager.isButtonPressed("left") // True
(static) MouseManager#isButtonDownByButtonCode(button) → {boolean}
Returns if the button is pressed by the button code.
Name | Type | Description |
---|---|---|
button | string | | The button code |
- Source
True if the button is pressed
- Type:
- boolean
DOM.MouseManager.isButtonDownByName(2) // True
(static) MouseManager#isButtonDownByName(button) → {boolean}
Returns if the button is pressed by the button name.
Name | Type | Description |
---|---|---|
button | string | | The button name |
- Source
True if the button is pressed
- Type:
- boolean
DOM.MouseManager.isButtonDownByName("left") // True