Low-level input device API.
For more generic cases use sensor-based API.
- Source:
Summary
Members
- DEVICE_GYRO
- DEVICE_HMD
- DEVICE_KEYBOARD
- DEVICE_MOUSE
- DEVICE_TOUCH
- GMPD_AXIS_0
- GMPD_AXIS_1
- GMPD_AXIS_2
- GMPD_AXIS_3
- GMPD_AXIS_4
- GMPD_AXIS_5
- GMPD_AXIS_6
- GMPD_AXIS_7
- GMPD_AXIS_8
- GMPD_AXIS_9
- GMPD_AXIS_10
- GMPD_AXIS_11
- GMPD_BUTTON_0
- GMPD_BUTTON_1
- GMPD_BUTTON_2
- GMPD_BUTTON_3
- GMPD_BUTTON_4
- GMPD_BUTTON_5
- GMPD_BUTTON_6
- GMPD_BUTTON_7
- GMPD_BUTTON_8
- GMPD_BUTTON_9
- GMPD_BUTTON_10
- GMPD_BUTTON_11
- GMPD_BUTTON_12
- GMPD_BUTTON_13
- GMPD_BUTTON_14
- GMPD_BUTTON_15
- GMPD_BUTTON_16
- GMPD_BUTTON_17
- GMPD_BUTTON_18
- GMPD_BUTTON_19
- GMPD_BUTTON_20
- GMPD_BUTTON_21
- GMPD_BUTTON_22
- GMPD_BUTTON_23
- GMPD_BUTTON_24
- GMPD_BUTTON_25
- GMPD_GRIPS_BUTTON
- GMPD_MENU_BUTTON
- GMPD_TRACKPAD_BUTTON
- GMPD_TRIGGER_BUTTON
- GYRO_ORIENTATION_ANGLES
- GYRO_ORIENTATION_QUAT
- HMD_BASELINE_DIST
- HMD_BEVEL_SIZE
- HMD_DISTORTION
- HMD_EYE_DISTANCE
- HMD_NON_WEBVR
- HMD_ORIENTATION_QUAT
- HMD_POSITION
- HMD_SCREEN_HEIGHT
- HMD_SCREEN_LENS_DIST
- HMD_SCREEN_WIDTH
- HMD_WEBVR1
- HMD_WEBVR1_1
- HMD_WEBVR_DESKTOP
- HMD_WEBVR_MOBILE
- HMD_WEBVR_TYPE
- KEYBOARD_DOWN
- KEYBOARD_UP
- MOUSE_DOWN_WHICH
- MOUSE_LOCATION
- MOUSE_UP_WHICH
- MOUSE_WHEEL
- TOUCH_END
- TOUCH_MOVE
- TOUCH_START
Methods
- add_click_listener(element, callback)
- attach_param_cb(device, param, cbopt)
- can_use_device(type) → {boolean}
- check_enable_gamepad_indices() → {Array}
- detach_param_cb(device, param, cbopt)
- disable_split_screen() → {boolean}
- enable_split_screen(camobj) → {boolean}
- get_device_by_type_element(type, elementnullable) → (nullable) {Object}
- get_gamepad_orientation(gamepad_id, dest) → {Quat}
- get_gamepad_position(gamepad_id, dest) → {Vec3}
- get_moved_gmpd_axis(gamepad_id) → {number}
- get_pressed_gmpd_btn(gamepad_id) → {number}
- get_value_param(device, param) → {number|boolean|null}
- get_vector_param(device, param, dest) → (nullable) {Float32Array}
- get_vr_controller_id(controller_id) → {number}
- register_device()
- remove_click_listener(element, callback)
- request_fullscreen_hmd()
- reset_device(device)
- set_gamepad_key(gamepad_id, btn, key)
- switch_prevent_default(device, prevent_default)
Type Definitions
- DeviceConfig
- DeviceHMDType
- DeviceParameterAsync
- DeviceType
- DeviceValueParameterSync
- DeviceVectorParameterSync
- GyroscopeAnglesCallback(angles)
- GyroscopeQuatCallback(quat)
- KeyboardDownCallback(key_code)
- KeyboardUpCallback(key_code)
- MouseDownWhichCallback(which)
- MouseLocationCallback(location)
- MouseUpWhichCallback(which)
- MouseWheelCallback(delta)
- TouchEndCallback(touches)
- TouchMoveCallback(touches)
- TouchStartCallback(touches)
Detailed Description
Members
DEVICE_GYRO
DEVICE_HMD
DEVICE_KEYBOARD
DEVICE_MOUSE
DEVICE_TOUCH
GMPD_AXIS_0
GMPD_AXIS_1
GMPD_AXIS_2
GMPD_AXIS_3
GMPD_AXIS_4
GMPD_AXIS_5
GMPD_AXIS_6
GMPD_AXIS_7
GMPD_AXIS_8
GMPD_AXIS_9
GMPD_AXIS_10
GMPD_AXIS_11
GMPD_BUTTON_0
GMPD_BUTTON_1
GMPD_BUTTON_2
GMPD_BUTTON_3
GMPD_BUTTON_4
GMPD_BUTTON_5
GMPD_BUTTON_6
GMPD_BUTTON_7
GMPD_BUTTON_8
GMPD_BUTTON_9
GMPD_BUTTON_10
GMPD_BUTTON_11
GMPD_BUTTON_12
GMPD_BUTTON_13
GMPD_BUTTON_14
GMPD_BUTTON_15
GMPD_BUTTON_16
GMPD_BUTTON_17
GMPD_BUTTON_18
GMPD_BUTTON_19
GMPD_BUTTON_20
GMPD_BUTTON_21
GMPD_BUTTON_22
GMPD_BUTTON_23
GMPD_BUTTON_24
GMPD_BUTTON_25
GMPD_GRIPS_BUTTON
GMPD_MENU_BUTTON
GMPD_TRACKPAD_BUTTON
GMPD_TRIGGER_BUTTON
GYRO_ORIENTATION_ANGLES
Parameter of gyroscope orientation angles.
Type:
- Source:
GYRO_ORIENTATION_QUAT
Parameter of gyroscope orientation quaternion.
Type:
- Source:
HMD_BASELINE_DIST
HMD_BEVEL_SIZE
HMD_DISTORTION
HMD_EYE_DISTANCE
HMD_NON_WEBVR
HMD_ORIENTATION_QUAT
Parameter of HMD orientation quaternion.
Type:
- Source:
HMD_POSITION
HMD_SCREEN_HEIGHT
HMD_SCREEN_LENS_DIST
HMD_SCREEN_WIDTH
HMD_WEBVR1
HMD_WEBVR1_1
HMD_WEBVR_DESKTOP
HMD_WEBVR_MOBILE
HMD_WEBVR_TYPE
KEYBOARD_DOWN
KEYBOARD_UP
MOUSE_DOWN_WHICH
MOUSE_LOCATION
Parameter of the mouse pointer coordinates.
Type:
- Source:
MOUSE_UP_WHICH
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
- Use module:screen.exit_split_screen instead
- 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
- Use module:screen.request_split_screen instead
- 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_position(gamepad_id, dest) → {Vec3}
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
- Use module:screen.request_fullscreen_hmd instead
- 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
DeviceHMDType
DeviceParameterAsync
Type of the names of the asynchronous parameter of a device.
Type:
- number
- Source:
DeviceType
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);