Skip to content

Mouse Routines

Eric Johnson edited this page Mar 6, 2018 · 9 revisions

Momo makes it easy to interface with various mouse routines.


Momo.getMouseX()

Momo.getMouseX()

Returns the mouse's X coordinate.


Momo.getMouseY()

Momo.getMouseY()

Returns the mouse's Y coordinate.


Momo.getMouseZ()

Momo.getMouseZ()

Returns the value of the mouse's scroll wheel.


Momo.hideMouseCursor()

Momo.hideMouseCursor()

Hides the mouse cursor on the canvas.


Momo.showMouseCursor()

Momo.showMouseCursor()

Shows the mouse cursor on the canvas.


Momo.isMouseCursorHidden()

Momo.isMouseCursorHidden()

Checks if the mouse cursor is hidden.

Return Value

  • Returns true if the mouse cursor is hidden or false otherwise

Momo.isMouseFocused()

Momo.isMouseFocused()

Returns a Boolean for whether or not the mouse is within (hovering over) the main canvas' boundaries.

Return Value

  • Returns true if the mouse is within the canvas' boundaries or false otherwise

Momo.isMouseButtonUp()

Momo.isMouseButtonUp(button)

Returns a Boolean for whether or not the given button is up (not being held down).

Parameters

  • button – The mouse button in question

Return Value

  • Returns true if the button is not being held down or false otherwise

This methods fires continuously. For one-time button releases, Momo.isMouseButtonReleased() should be used instead.


Momo.isMouseButtonDown()

Momo.isMouseButtonDown(button)

Returns a Boolean for whether or not the given button is being held down.

Parameters

  • button – The mouse button in question

Return Value

  • Returns true if the button is being held down or false otherwise

This methods fires continuously. For one-time button presses, Momo.isMouseButtonPressed() should be used instead.


Momo.isMouseButtonPressed()

Momo.isMouseButtonPressed(button)

Returns a Boolean for whether or not the given button was pressed down.

Parameters

  • button – The mouse button in question

Return Value

  • True if the button was pressed or false otherwise

This methods fires once per mouse button press. For continuous firing, use Momo.isMouseButtonDown() instead.


Momo.isMouseButtonReleased()

Momo.isMouseButtonReleased(button)

Returns a Boolean for whether or not the given button was released.

Parameters

  • button – The mouse button in question

Return Value

  • True if the button was released or false otherwise

This methods fires once per mouse release press. For continuous firing, use Momo.isMouseButtonUp() instead.


Momo.lockMouse()

Momo.lockMouse()

Locks the mouse to the canvas.

Return Value

  • No return value

Example

// Lock the mouse to the canvas upon clicking on the canvas.
Momo.getCanvas().onclick = () => {

  Momo.lockMouse();
};

Momo.unlockMouse()

Momo.unlockMouse()

Unlocks the mouse from the canvas.

Return Value

  • No return value

Momo.isMouseLocked()

Momo.isMouseLocked()

Checks if the mouse is locked to the canvas.

Return Value

  • Returns true if the mouse is locked or false otherwise

Mouse Buttons

Strings representing the three mouse buttons (left, middle, and right) are to be used in conjunction with various mouse methods.

"left"
"right"
"middle"

For example, to check if the left mouse button has been released, the following would be used:

if (Momo.isMouseButtonReleased("left")) {

  // The left mouse button has been released.
}

Additionally, "any" can be used with any of the button-checking methods. This literally checks whether or not any button matches a given event. Keep in mind that using "any" in conjunction with Momo.isMouseButtonUp() will return true unless all mouse buttons (left, right, and middle) are pressed down.

Clone this wiki locally