Module: input

Low-level input device API. For more generic cases use sensor-based API.

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:

GMPD_GRIPS_BUTTON

Gamepad grips ID.
Type:
  • number
Source:

GMPD_MENU_BUTTON

Gamepad grips ID.
Type:
  • number
Source:

GMPD_TRACKPAD_BUTTON

Gamepad track pad ID.
Type:
  • number
Source:

GMPD_TRIGGER_BUTTON

Gamepad trigger ID.
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_LENS_DIST

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

HMD_SCREEN_WIDTH

Parameter of mobile screen width.
Type:
Source:

HMD_WEBVR1

WebVR API 1.0
Type:
Source:

HMD_WEBVR1_1

WebVR API 1.1
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

add_click_listener(element, callback)

Register the listener on the click event. Callback is called on right after click on element (without 300ms delay).
Parameters:
Name Type Description
element HTMLElement DOM element.
callback Callback Callback.
Source:

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
Deprecated
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
Deprecated
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_gamepad_orientation(gamepad_id, dest) → {Quat}

Get gamepad orientation.
Parameters:
Name Type Description
gamepad_id number Gamepad identifier (Connected device number 0-3).
dest Quat Destination vector.
Returns:
Gamepad orientation.
Type
Quat
Source:

get_gamepad_position(gamepad_id, dest) → {Vec3}

Get gamepad position.
Parameters:
Name Type Description
gamepad_id number Gamepad identifier (Connected device number 0-3).
dest Vec3 Destination vector.
Returns:
Gamepad position.
Type
Vec3
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|null}

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 | null
Source:

get_vector_param(device, param, dest) → (nullable) {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:

get_vr_controller_id(controller_id) → {number}

Get gamepad id of VR controller.
Parameters:
Name Type Description
controller_id number VR controller id.
Returns:
Gamepad id.
Type
number
Source:
Example
var m_input = require("input");

// get the id of the first VR controller (among all gamepads)
var vr_id = m_input.get_vr_controller_id(0);

register_device()

Register device. Right now it should be used for DEVICE_HMD.
Deprecated
  • Not needed anymore.
Source:

remove_click_listener(element, callback)

Unregister the listener registered with input.add_click_listener.
Parameters:
Name Type Description
element HTMLElement DOM element.
callback Callback Callback.
Source:

request_fullscreen_hmd()

Request fullscreen mode.
Deprecated
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 (in radians) 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);