API Reference

Class List

pc.Mouse

A Mouse Device, bound to a DOM Element.

Summary

Static Methods

isPointerLockedCheck if the mouse pointer has been locked, using pc.Mouse#enabledPointerLock

Methods

attachAttach mouse events to an Element.
detachRemove mouse events from the element that it is attached to
disableContextMenuDisable the context menu usually activated with right-click
disablePointerLockReturn control of the mouse cursor to the user
enableContextMenuEnable the context menu usually activated with right-click.
enablePointerLockRequest that the browser hides the mouse cursor and locks the mouse to the element.
isPressedReturns true if the mouse button is currently pressed
updateUpdate method, should be called once per frame
wasPressedReturns true if the mouse button was pressed this frame (since the last call to update).
wasReleasedReturns true if the mouse button was released this frame (since the last call to update).

Events

mousedownFired when a mouse button is pressed
mousemoveFired when the mouse is moved
mouseupFired when a mouse button is released
mousewheelFired when a mouse wheel is moved

Details

Static Methods

isPointerLocked()

Check if the mouse pointer has been locked, using pc.Mouse#enabledPointerLock

Returns

Boolean True if locked

Constructor

Mouse([element])

Create a new Mouse device

Parameters

elementElementThe Element that the mouse events are attached to

Methods

attach(element)

Attach mouse events to an Element.

Parameters

elementElement

detach()

Remove mouse events from the element that it is attached to

disableContextMenu()

Disable the context menu usually activated with right-click

disablePointerLock([success])

Return control of the mouse cursor to the user

Parameters

successfunctionFunction called when the mouse lock is disabled

enableContextMenu()

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

enablePointerLock([success], [error])

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

successfunctionFunction called if the request for mouse lock is successful.
errorfunctionFunction called if the request for mouse lock is unsuccessful.

isPressed(button)

Returns true if the mouse button is currently pressed

Parameters

buttonpc.MOUSEBUTTON

Returns

Boolean True if the mouse button is current pressed

update(dt)

Update method, should be called once per frame

Parameters

dtObject

wasPressed(button)

Returns true if the mouse button was pressed this frame (since the last call to update).

Parameters

buttonpc.MOUSEBUTTON

Returns

Boolean True if the mouse button was pressed since the last update

wasReleased(button)

Returns true if the mouse button was released this frame (since the last call to update).

Parameters

buttonpc.MOUSEBUTTON

Returns

Boolean True if the mouse button was released since the last update

Events

mousedown

Fired when a mouse button is pressed

Parameters

eventpc.MouseEventThe MouseEvent object

mousemove

Fired when the mouse is moved

Parameters

eventpc.MouseEventThe MouseEvent object

mouseup

Fired when a mouse button is released

Parameters

eventpc.MouseEventThe MouseEvent object

mousewheel

Fired when a mouse wheel is moved

Parameters

eventpc.MouseEventThe MouseEvent object