Class: Mouse

pc.Mouse

A Mouse Device, bound to a DOM Element.

Constructor

new Mouse(elementopt)

Create a new Mouse device
Parameters:
Name Type Attributes Description
element Element <optional>
The Element that the mouse events are attached to
Source:

Methods

(static) isPointerLocked() → {Boolean}

Check if the mouse pointer has been locked, using pc.Mouse#enabledPointerLock
Source:
Returns:
True if locked
Type
Boolean

attach(element)

Attach mouse events to an Element.
Parameters:
Name Type Description
element Element The DOM element to attach the mouse to.
Source:

detach()

Remove mouse events from the element that it is attached to
Source:

disableContextMenu()

Disable the context menu usually activated with right-click
Source:

disablePointerLock(successopt)

Return control of the mouse cursor to the user
Parameters:
Name Type Attributes Description
success function <optional>
Function called when the mouse lock is disabled
Source:

enableContextMenu()

Enable the context menu usually activated with right-click. This option is active by default.
Source:

enablePointerLock(successopt, erroropt)

Request that the browser hides the mouse cursor and locks the mouse to the element. Allowing raw access to mouse movement input without risking the mouse exiting the element. Notes:
  • In some browsers this will only work when the browser is running in fullscreen mode. See pc.Application#enableFullscreen
  • Enabling pointer lock can only be initiated by a user action e.g. in the event handler for a mouse or keyboard input.
Parameters:
Name Type Attributes Description
success function <optional>
Function called if the request for mouse lock is successful.
error function <optional>
Function called if the request for mouse lock is unsuccessful.
Source:

isPressed(button) → {Boolean}

Returns true if the mouse button is currently pressed
Parameters:
Name Type Description
button Number The mouse button to test. Can be:
Source:
Returns:
True if the mouse button is current pressed
Type
Boolean

update()

Update method, should be called once per frame
Source:

wasPressed(button) → {Boolean}

Returns true if the mouse button was pressed this frame (since the last call to update).
Parameters:
Name Type Description
button Number The mouse button to test. Can be:
Source:
Returns:
True if the mouse button was pressed since the last update
Type
Boolean

wasReleased(button) → {Boolean}

Returns true if the mouse button was released this frame (since the last call to update).
Parameters:
Name Type Description
button Number The mouse button to test. Can be:
Source:
Returns:
True if the mouse button was released since the last update
Type
Boolean

Events

mousedown

Fired when a mouse button is pressed
Parameters:
Name Type Description
event pc.MouseEvent The MouseEvent object
Source:

mousemove

Fired when the mouse is moved
Parameters:
Name Type Description
event pc.MouseEvent The MouseEvent object
Source:

mouseup

Fired when a mouse button is released
Parameters:
Name Type Description
event pc.MouseEvent The MouseEvent object
Source:

mousewheel

Fired when a mouse wheel is moved
Parameters:
Name Type Description
event pc.MouseEvent The MouseEvent object
Source: