This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

engine.input Functions

Warning
UnigineScript is deprecated and will be removed in future releases. Please consider using C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScipt is not guaranteed, as the current level of support assumes only fixing critical issues.

The Input class contains functions for simple manual handling of user inputs using a keyboard, a mouse or a game pad.

This class represents a singleton of the Engine class and can be accessed via the following way:

Source code (UnigineScript)
engine.input

Usage Example#

The following example shows a way to move and rotate a node by using the Input class:

Source code (UnigineScript)
int update() {
	float move_speed = 1.0f;
	float turn_speed = 5.0f;

	if (engine.console.getActivity())
		return;

	vec3 direction = node.getWorldDirection(AXIS_Y);
	if (engine.input.isKeyPressed(INPUT_KEY_UP) || engine.input.isKeyPressed(INPUT_KEY_W))
	{
		node.setWorldPosition(node.getWorldPosition() + direction * move_speed * engine.game.getIFps());
	}

	if (engine.input.isKeyPressed(INPUT_KEY_DOWN) || engine.input.isKeyPressed(INPUT_KEY_S))
	{
		node.setWorldPosition(node.getWorldPosition() - direction * move_speed * engine.game.getIFps());
	}

	if (engine.input.isKeyPressed(INPUT_KEY_LEFT) || engine.input.isKeyPressed(INPUT_KEY_A))
	{
		node.rotate(0.0f, 0.0f, turn_speed * engine.game.getIFps());
	}

	if (engine.input.isKeyPressed(INPUT_KEY_RIGHT) || engine.input.isKeyPressed(INPUT_KEY_D))
	{
		node.rotate(0.0f, 0.0f, -turn_speed * engine.game.getIFps());
	}

	return 1;
}

Input Class

Members


ivec2 engine.input.getMouseCoord ( ) #

Returns a vector containing integer values of mouse pointer position.

Return value

Integer mouse pointer position.

ivec2 engine.input.getMouseCoordDelta ( ) #

Returns a vector containing integer screen position change of the mouse pointer along the X and Y axes — the difference between the values in the previous and the current frames.

Return value

Integer mouse pointer position delta.

vec2 engine.input.getMouseDelta ( ) #

Returns a vector containing float screen position change of the mouse pointer along the X and Y axes — the difference between the values in the previous and the current frames.
Notice
Float values are useful for rotation and other smooth transformations.

Return value

Float mouse pointer position delta.

int engine.input.getMouseWheel ( ) #

Returns the current mouse scroll value. Negative values correspond to scrolling downwards; positive values correspond to scrolling upwards; the value is zero when the mouse wheel is not scrolled.

Return value

Mouse scroll value in the [-1;1] range.

int engine.input.getMouseWheelHorizontal ( ) #

Returns the current horizontal mouse scroll value.

Return value

Horizontal mouse scroll value in the [-1;1] range.

int engine.input.getCountGamePads ( ) #

Returns the number of all game pads.

Return value

Number of all game pads.

InputGamePad engine.input.getGamePad ( int num ) #

Returns a game pad of the given index.

Arguments

  • int num - index.

Return value

InputGamepad object.

int engine.input.getCountActiveGamePads ( ) #

Returns the number of active game pads.

Return value

Number of active game pads.

InputGamePad engine.input.getActiveGamePad ( int num ) #

Returns an active game pad of the given index.

Arguments

  • int num - index.

Return value

InputGamePad object.

int engine.input.isKeyPressed ( int key ) #

Returns a value indicating if the given key is pressed or not. Check this value to perform continuous actions.
Source code (UnigineScript)
if (engine.input.isKeyPressed(INPUT_KEY_RETURN)) {
	log.message("enter key is held down\n");
}

Arguments

Return value

1 if the key is pressed; otherwise, 0.

int engine.input.isKeyDown ( int key ) #

Returns a value indicating if the given key was pressed during the current frame or not. Check this value to perform one-time actions on pressing a key.
Source code (UnigineScript)
if (engine.input.isKeyDown(INPUT_KEY_KEY_SPACE)) {
	log.message("space key was pressed\n");
}

Arguments

Return value

1 during the first frame when the key was pressed, 0 for the following ones until it is released and pressed again.

int engine.input.isKeyUp ( int key ) #

Returns a value indicating if the given key was released during the current frame or not. Check this value to perform one-time actions on releasing a key.
Source code (UnigineScript)
if (engine.input.isKeyUp(INPUT_KEY_F)) {
	log.message("f key was released\n");
}

Arguments

Return value

1 during the first frame when the key was released; otherwise, 0.

int engine.input.isMouseButtonPressed ( int button ) #

Returns a value indicating if the given mouse button is pressed or not. Check this value to perform continuous actions.
Source code (UnigineScript)
if (engine.input.isMouseButtonPressed(INPUT_MOUSE_BUTTON_LEFT)) {
	log.message("left mouse button is held down\n");
}

Arguments

Return value

1 if the mouse button is pressed; otherwise, 0.

int engine.input.isMouseButtonDown ( int button ) #

Returns a value indicating if the given mouse button was pressed during the current frame or not. Check this value to perform one-time actions on pressing a mouse button.
Source code (UnigineScript)
if (engine.input.isMouseButtonDown(INPUT_MOUSE_BUTTON_LEFT)) {
	log.message("left mouse button was pressed\n");
}

Arguments

Return value

1 during the first frame when the mouse button was released; otherwise, 0.

int engine.input.isMouseButtonUp ( int button ) #

Returns a value indicating if the given mouse button was released during the current frame or not. Check this value to perform one-time actions on releasing a mouse button.
Source code (UnigineScript)
if (engine.input.isMouseButtonUp(INPUT_MOUSE_BUTTON_LEFT)) {
	log.message("left mouse button was released\n");
}

Arguments

Return value

1 during the first frame when the mouse button was released; otherwise, 0.

void engine.input.setMouseHandle ( int handle ) #

Sets the mouse behavior mode.

Arguments

int engine.input.getMouseHandle ( ) #

Returns the mouse behavior mode.

Return value

Mouse behavior mode, one of the MOUSE_HANDLE_* values.
Last update: 2020-04-10
Build: ()