UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and 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
CIGI Client Plugin
Rendering-Related Classes

Unigine::Input Class

Header: #include <UnigineInput.h>

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

This class represents an engine's singleton and can be accessed via the following way:

Source code (C++)
Input::get()

Usage Example#

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

Source code (C++)
int AppWorldLogic::update()
{
		float move_speed = 1.0f;
		float turn_speed = 5.0f;

		NodePtr node = NodeDummy::create()->getNode();

		if (Console::get()->getActivity())
			return;

		vec3 direction = node->getWorldDirection(AXIS_Y);
		if (Input::get()->isKeyPressed(Input::KEY_UP) || Input::get()->isKeyPressed(Input::KEY_W))
		{
			node->setWorldPosition(node->getWorldPosition() + Vec3(direction * move_speed * Game::get()->getIFps()));
		}

		if (Input::get()->isKeyPressed(Input::KEY_DOWN) || Input::get()->isKeyPressed(Input::KEY_S))
		{
			node->setWorldPosition(node->getWorldPosition() - Vec3(direction * move_speed * Game::get()->getIFps()));
		}

		if (Input::get()->isKeyPressed(Input::KEY_LEFT) || Input::get()->isKeyPressed(Input::KEY_A))
		{
			node->rotate(0.0f, 0.0f, turn_speed * Game::get()->getIFps());
		}

		if (Input::get()->isKeyPressed(Input::KEY_RIGHT) || Input::get()->isKeyPressed(Input::KEY_D))
		{
			node->rotate(0.0f, 0.0f, -turn_speed * Game::get()->getIFps());
		}
	return 1;
}

Input Class

Members


Input * get ( ) #

Returns a pointer to the Input instance.

Return value

Input instance.

Math::ivec2 getMouseCoord ( ) #

Returns a vector containing integer values of mouse pointer position.

Return value

Integer mouse pointer position.

Math::ivec2 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.

Math::vec2 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 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 getMouseWheelDelta ( ) #

Returns the scroll change of the mouse wheel — the difference between the values in the previous and the current frames.

Return value

Mouse scroll delta value.

int getMouseWheelHorizontal ( ) #

Returns the current horizontal mouse scroll value.

Return value

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

int getMouseWheelHorizontalDelta ( ) #

Returns the horizontal scroll change of the mouse wheel — the difference between the values in the previous and the current frames.

Return value

Horizontal mouse scroll delta value.

void setMouseGrab ( int grab ) #

Sets the value indicating if the mouse pointer is bound to the application window.

Arguments

  • int grab - 1 if the mouse cannot leave the application window; otherwise, 0.

int getMouseGrab ( ) #

Returns the value indicating if the mouse pointer is bound to the application window.

Return value

1 if the mouse cannot leave the application window; otherwise, 0.

void setMouseShow ( int show ) #

Sets the value indicating if the OS mouse pointer should be displayed.

Arguments

  • int show - 1 if the OS mouse pointer should be displayed; 0 if the application cursor is used only.

int getMouseShow ( ) #

Returns the value indicating if the OS mouse pointer should be displayed.

Return value

1 if the OS mouse pointer should be displayed; 0 if the application cursor is used only.

int getCountGamePads ( ) #

Returns the number of all game pads.

Return value

Number of all game pads.

Ptr<InputGamePad> getGamePad ( int num ) #

Returns a game pad of the given index.

Arguments

  • int num - index.

Return value

InputGamepad object.

int getCountActiveGamePads ( ) #

Returns the number of active game pads.

Return value

Number of active game pads.

Ptr<InputGamePad> getActiveGamePad ( int num ) #

Returns an active game pad of the given index.

Arguments

  • int num - index.

Return value

InputGamePad object.

int isKeyPressed ( int key ) #

Returns a value indicating if the given key is pressed or not. Check this value to perform continuous actions.
Source code (C++)
if (Input::get()->isKeyPressed(Input::KEY_RETURN)) {
	Log::message("enter key is held down\n");
}

Arguments

  • int key - One of the preset KEY_ codes.

Return value

1 if the key is pressed; otherwise, 0.

int 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 (C++)
if (Input::get()->isKeyDown(Input::KEY_KEY_SPACE)) {
	Log::message("space key was pressed\n");
}

Arguments

  • int key - One of the preset KEY_ codes.

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 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 (C++)
if (Input::get()->isKeyUp(Input::KEY_F)) {
	Log::message("f key was released\n");
}

Arguments

  • int key - One of the preset KEY_ codes.

Return value

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

int 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 (C++)
if (Input::get()->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 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 (C++)
if (Input::get()->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 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 (C++)
if (Input::get()->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.
Last update: 2019-11-28