Module: input

Input device API
Source:

Summary

Members

Methods

Type Definitions

Detailed Description

Members

DEVICE_GYRO

Gyroscope device type.
Type:
Source:

DEVICE_HMD

Head mounted device type.
Type:
Source:

DEVICE_KEYBOARD

Keyboard device type.
Type:
Source:

DEVICE_MOUSE

Mouse device type.
Type:
Source:

DEVICE_TOUCH

Touch device type.
Type:
Source:

GMPD_AXIS_0

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_1

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_2

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_3

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_4

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_5

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_6

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_7

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_8

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_9

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_10

Gamepad axis.
Type:
  • Number
Source:

GMPD_AXIS_11

Gamepad axis.
Type:
  • Number
Source:

GMPD_BUTTON_0

Gamepad face panel down button ID.
Type:
  • Number
Source:

GMPD_BUTTON_1

Gamepad face panel right button ID.
Type:
  • Number
Source:

GMPD_BUTTON_2

Gamepad face panel left button ID.
Type:
  • Number
Source:

GMPD_BUTTON_3

Gamepad face panel up button ID.
Type:
  • Number
Source:

GMPD_BUTTON_4

Gamepad left top shoulder button ID.
Type:
  • Number
Source:

GMPD_BUTTON_5

Gamepad right top shoulder button ID.
Type:
  • Number
Source:

GMPD_BUTTON_6

Gamepad left bottom shoulder button ID.
Type:
  • Number
Source:

GMPD_BUTTON_7

Gamepad right bottom shoulder button ID.
Type:
  • Number
Source:

GMPD_BUTTON_8

Gamepad select/back button ID.
Type:
  • Number
Source:

GMPD_BUTTON_9

Gamepad start/forward button ID.
Type:
  • Number
Source:

GMPD_BUTTON_10

Gamepad left analog button ID.
Type:
  • Number
Source:

GMPD_BUTTON_11

Gamepad right analog button ID.
Type:
  • Number
Source:

GMPD_BUTTON_12

Gamepad D-pad up button ID.
Type:
  • Number
Source:

GMPD_BUTTON_13

Gamepad D-pad down button ID.
Type:
  • Number
Source:

GMPD_BUTTON_14

Gamepad D-pad left button ID.
Type:
  • Number
Source:

GMPD_BUTTON_15

Gamepad D-pad right button ID.
Type:
  • Number
Source:

GMPD_BUTTON_16

Gamepad main button ID.
Type:
  • Number
Source:

GMPD_BUTTON_17

Gamepad button.
Type:
  • Number
Source:

GMPD_BUTTON_18

Gamepad button.
Type:
  • Number
Source:

GMPD_BUTTON_19

Gamepad button.
Type:
  • Number
Source:

GMPD_BUTTON_20

Gamepad button.
Type:
  • Number
Source:

GMPD_BUTTON_21

Gamepad button.
Type:
  • Number
Source:

GMPD_BUTTON_22

Gamepad button.
Type:
  • Number
Source:

GMPD_BUTTON_23

Gamepad button.
Type:
  • Number
Source:

GMPD_BUTTON_24

Gamepad button.
Type:
  • Number
Source:

GMPD_BUTTON_25

Gamepad button.
Type:
  • Number
Source:

GYRO_ORIENTATION_ANGLES

Parameter of gyroscope orientation angles.
Type:
Source:

GYRO_ORIENTATION_QUAT

Parameter of gyroscope orientation quaternion.
Type:
Source:

HMD_BASELINE_DIST

Parameter of HMD baseline distance.
Type:
Source:

HMD_BEVEL_SIZE

Parameter of mobile bevel size.
Type:
Source:

HMD_DISTORTION

Parameter of HMD distortion coefficients.
Type:
Source:

HMD_EYE_DISTANCE

Parameter of HMD eye distance.
Type:
Source:

HMD_NON_WEBVR

Non-WebVR HMD
Type:
Source:

HMD_ORIENTATION_QUAT

Parameter of HMD orientation quaternion.
Type:
Source:

HMD_POSITION

Parameter of HMD position.
Type:
Source:

HMD_SCREEN_HEIGHT

Parameter of mobile screen height.
Type:
Source:

HMD_SCREEN_LENSE_DIST

Parameter of HMD screen to lense distance.
Type:
Source:

HMD_SCREEN_WIDTH

Parameter of mobile screen width.
Type:
Source:

HMD_WEBVR1

WebVR API 1.0
Type:
Source:

HMD_WEBVR_DESKTOP

WebVR (old) desktop HMD
Type:
Source:

HMD_WEBVR_MOBILE

WebVR (old) mobile HMD
Type:
Source:

HMD_WEBVR_TYPE

Parameter of HMD type.
Type:
Source:

KEYBOARD_DOWN

Parameter of the keyboard downed key.
Type:
Source:

KEYBOARD_UP

Parameter of the keyboard upped key.
Type:
Source:

MOUSE_DOWN_WHICH

Parameter of the mouse downed key.
Type:
Source:

MOUSE_LOCATION

Parameter of the mouse pointer coordinates.
Type:
Source:

MOUSE_UP_WHICH

Parameter of the mouse upped key.
Type:
Source:

MOUSE_WHEEL

Parameter of the vertical scroll amount.
Type:
Source:

TOUCH_END

Parameter of ended touch point list on the touch surface.
Type:
Source:

TOUCH_MOVE

Parameter of moving touch list on the touch surface.
Type:
Source:

TOUCH_START

Parameter of started touch point list on the touch surface.
Type:
Source:

Methods

attach_param_cb(device, param, cbopt)

Attach callback to the device parameter. It is called when parameter is changed.
Parameters:
Name Type Attributes Default Description
device Object Device object. Use input.get_device_by_type_element to obtain it.
param DeviceParameterAsync Name of the device parameter.
cb MouseLocationCallback | MouseDownWhichCallback | MouseUpWhichCallback | MouseWheelCallback | KeyboardDownCallback | KeyboardUpCallback | TouchStartCallback | TouchMoveCallback | TouchEndCallback | GyroscopeQuatCallback | GyroscopeAnglesCallback <optional>
null Callback.
Source:

can_use_device(type) → {Boolean}

Check if the device can be used.
Parameters:
Name Type Description
type DeviceType Device type.
Returns:
Result of the check
Type
Boolean
Source:

check_enable_gamepad_indices() → {Array}

Check available gamepads indices.
Returns:
Numeric array with indices
Type
Array
Source:

detach_param_cb(device, param, cbopt)

Detach callback from the device parameter.
Parameters:
Name Type Attributes Default Description
device Object Device object. Use input.get_device_by_type_element to obtain it.
param DeviceParameterAsync Name of the device parameter.
cb MouseLocationCallback | MouseDownWhichCallback | MouseUpWhichCallback | MouseWheelCallback | KeyboardDownCallback | KeyboardUpCallback | TouchStartCallback | TouchMoveCallback | TouchEndCallback | GyroscopeQuatCallback | GyroscopeAnglesCallback <optional>
null Callback.
Source:

disable_split_screen() → {Boolean}

Disable "split screen" mode.
Returns:
"Split screen" mode is disabled.
Type
Boolean
Source:

enable_split_screen(camobj) → {Boolean}

Enable "split screen" mode.
Parameters:
Name Type Description
camobj Object3D Camera 3D-object.
Returns:
"Split screen" mode is enabled.
Type
Boolean
Source:

get_device_by_type_element(type, elementnullable) → (nullable) {Object}

Get device object by associated device type and DOM element. If device is not available, then return null.
Parameters:
Name Type Attributes Description
type DeviceType Device type.
element HTMLElement <nullable>
HTML element to add event listeners to.
Returns:
Device object.
Type
Object
Source:

get_moved_gmpd_axis(gamepad_id) → {Number}

Get moved axis key value.
Parameters:
Name Type Description
gamepad_id Number Gamepad identifier (Connected device number 0-3).
Returns:
Moved axis key value.
Type
Number
Source:

get_pressed_gmpd_btn(gamepad_id) → {Number}

Get pressed button key value.
Parameters:
Name Type Description
gamepad_id Number Gamepad identifier (Connected device number 0-3).
Returns:
Pressed button key value.
Type
Number
Source:

get_value_param(device, param) → {Number|Boolean}

Get parameter value.
Parameters:
Name Type Description
device Object Device object. Use input.get_device_by_type_element to obtain it.
param DeviceValueParameterSync Name of the device value parameter.
Returns:
Parameter value.
Type
Number | Boolean
Source:

get_vector_param(device, param, dest) → {Float32Array}

Get parameter vector.
Parameters:
Name Type Description
device Object Device object. Use input.get_device_by_type_element to obtain it.
param DeviceVectorParameterSync Name of the device vector parameter.
dest Float32Array Destination vector.
Returns:
Destination vector.
Type
Float32Array
Source:

register_device(device)

Register device. Right now it should be used for DEVICE_HMD.
Parameters:
Name Type Description
device Object Device object. Use input.get_device_by_type_element to obtain it.
Deprecated:
  • Not needed anymore.
Source:

reset_device(device)

Reset device. The device parameters values return to zero. Right now it should be used for DEVICE_HMD.
Parameters:
Name Type Description
device Object Device object. Use input.get_device_by_type_element to obtain it.
Source:

set_gamepad_key(gamepad_id, btn, key)

Set gamepad button key value.
Parameters:
Name Type Description
gamepad_id Number Connected gamepad number.
btn Number Button or axis identifier.
key Number Button key value.
Source:

switch_prevent_default(device, prevent_default)

Switch triggering of the browser default actions for registered events.
Parameters:
Name Type Description
device Object Device object. Use input.get_device_by_type_element to obtain it.
prevent_default Boolean Prevent default flag.
Source:

Type Definitions

DeviceConfig

Type of the names of the device config.
Type:
  • Number
Source:

DeviceHMDType

HMD type enum. Value of input.HMD_WEBVR_TYPE.
Type:
  • Number
Source:

DeviceParameterAsync

Type of the names of the asynchronous parameter of a device.
Type:
  • Number
Source:

DeviceType

Device type enum.
Type:
  • Number
Source:

DeviceValueParameterSync

Type of the names of the synchronous value parameter of a device.
Type:
  • Number
Source:

DeviceVectorParameterSync

Type of the names of the synchronous vector parameter of a device.
Type:
  • Float32Array
Source:

GyroscopeAnglesCallback(angles)

The callback for the Euler angles of the gyroscope orientation corresponding to the GYRO_ORIENTATION_ANGLES param.
Parameters:
Name Type Description
angles Euler Euler angles corresponding to the gyroscope orientation.
Source:
Example
var m_input = require("input");

var gyroscope_angles_cb = function(angles) {
    console.log("Gyroscope orientation Euler angles are " + angles);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_GYRO);
m_input.attach_param_cb(device, m_input.GYRO_ORIENTATION_ANGLES, gyroscope_angles_cb);

GyroscopeQuatCallback(quat)

The callback for the quaternion of the gyroscope orientation corresponding to the GYRO_ORIENTATION_QUAT param.
Parameters:
Name Type Description
quat Quat Quaternion vector corresponding to the gyroscope orientation.
Source:
Example
var m_input = require("input");

var gyroscope_quat_cb = function(quat) {
    console.log("Gyroscope orientation quaternion is " + quat);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_GYRO);
m_input.attach_param_cb(device, m_input.GYRO_ORIENTATION_QUAT, gyroscope_quat_cb);

KeyboardDownCallback(key_code)

The callback for the pressed keyboard button corresponding to the KEYBOARD_DOWN param.
Parameters:
Name Type Description
key_code Number Number indicates button that was pressed on the keyboard (use constants KEY_* from module controls).
Source:
Example
var m_input = require("input");

var keyboard_down_cb = function(key_code) {
    console.log("Pressed keyboard button: " + key_code);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_KEYBOARD);
m_input.attach_param_cb(device, m_input.KEYBOARD_DOWN, keyboard_down_cb);

KeyboardUpCallback(key_code)

The callback for the released keyboard button corresponding to the KEYBOARD_UP param.
Parameters:
Name Type Description
key_code Number Number indicates button that was released on the keyboard (use constants KEY_* from module controls).
Source:
Example
var m_input = require("input");

var keyboard_up_cb = function(key_code) {
    console.log("Released keyboard button: " + key_code);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_KEYBOARD);
m_input.attach_param_cb(device, m_input.KEYBOARD_UP, keyboard_up_cb);

MouseDownWhichCallback(which)

The callback for the pressed mouse button corresponding to the MOUSE_DOWN_WHICH param.
Parameters:
Name Type Description
which Number Number indicates button that was pressed on the mouse (1 -- left button, 2 -- middle button, 3 -- right button).
Source:
Example
var m_input = require("input");

var mouse_down_which_cb = function(which) {
    console.log("Pressed button: " + which);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_MOUSE);
m_input.attach_param_cb(device, m_input.MOUSE_DOWN_WHICH, mouse_down_which_cb);

MouseLocationCallback(location)

The callback for the mouse location corresponding to the MOUSE_LOCATION param.
Parameters:
Name Type Description
location Float32Array List: the horizontal mouse coordinate, the vertical mouse coordinate.
Source:
Example
var m_input = require("input");

var mouse_location_cb = function(location) {
    console.log("The horizontal location: " + location[0]);
    console.log("The vertical location: " + location[1]);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_MOUSE);
m_input.attach_param_cb(device, m_input.MOUSE_LOCATION, mouse_location_cb);

MouseUpWhichCallback(which)

The callback for the released mouse button corresponding to the MOUSE_UP_WHICH param.
Parameters:
Name Type Description
which Number Number indicates button that was released on the mouse (1 -- left button, 2 -- middle button, 3 -- right button).
Source:
Example
var m_input = require("input");

var mouse_up_which_cb = function(which) {
    console.log("Released button: " + which);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_MOUSE);
m_input.attach_param_cb(device, m_input.MOUSE_UP_WHICH, mouse_up_which_cb);

MouseWheelCallback(delta)

The callback for the mouse scroll corresponding to the MOUSE_WHEEL param.
Parameters:
Name Type Description
delta Number The vertical mouse scroll amount.
Source:
Example
var m_input = require("input");

var mouse_wheel_cb = function(delta) {
    console.log("Scroll amount: " + delta);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_MOUSE);
m_input.attach_param_cb(device, m_input.MOUSE_WHEEL, mouse_wheel_cb);

TouchEndCallback(touches)

The callback for the end of touch surface contacting corresponding to the TOUCH_END param.
Parameters:
Name Type Description
touches Array List of touch objects corresponding to the contacting with the touch surface points.
Source:
Example
var m_input = require("input");

var touch_end_cb = function(touches) {
    for (var i = 0; i < touches.length; ++i)
         console.log("Touch contact " + touches[i].identifier + " has position" +
                 + " x: " + touches[i].clientX + " y: " + touches[i].clientY);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_TOUCH);
m_input.attach_param_cb(device, m_input.TOUCH_END, touch_end_cb);

TouchMoveCallback(touches)

The callback for the contact moving on the touch surface corresponding to the TOUCH_MOVE param.
Parameters:
Name Type Description
touches Array List of touch objects corresponding to the contacting with the touch surface points.
Source:
Example
var m_input = require("input");

var touch_move_cb = function(touches) {
    for (var i = 0; i < touches.length; ++i)
         console.log("Touch contact " + touches[i].identifier + " has position" +
                 + " x: " + touches[i].clientX + " y: " + touches[i].clientY);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_TOUCH);
m_input.attach_param_cb(device, m_input.TOUCH_MOVE, touch_move_cb);

TouchStartCallback(touches)

The callback for the start of touch surface contacting corresponding to the TOUCH_START param.
Parameters:
Name Type Description
touches Array List of touch objects corresponding to the contacting with the touch surface points.
Source:
Example
var m_input = require("input");

var touch_start_cb = function(touches) {
    for (var i = 0; i < touches.length; ++i)
         console.log("Touch contact " + touches[i].identifier + " has position" +
                 + " x: " + touches[i].clientX + " y: " + touches[i].clientY);
};
var device = m_input.get_device_by_type_element(m_input.DEVICE_TOUCH);
m_input.attach_param_cb(device, m_input.TOUCH_START, touch_start_cb);