This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
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
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

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.

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::isActive())
			return;

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

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

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

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

Input Class

Enums

KEY#

NameDescription
KEY_UNKNOWN = 0
KEY_DIGIT_0 = '0'The 0 key of the alphanumeric keyboard
KEY_DIGIT_1 = '1'The 1 key of the alphanumeric keyboard
KEY_DIGIT_2 = '2'The 2 key of the alphanumeric keyboard
KEY_DIGIT_3 = '3'The 3 key of the alphanumeric keyboard
KEY_DIGIT_4 = '4'The 4 key of the alphanumeric keyboard
KEY_DIGIT_5 = '5'The 5 key of the alphanumeric keyboard
KEY_DIGIT_6 = '6'The 6 key of the alphanumeric keyboard
KEY_DIGIT_7 = '7'The 7 key of the alphanumeric keyboard
KEY_DIGIT_8 = '8'The 8 key of the alphanumeric keyboard
KEY_DIGIT_9 = '9'The 9 key of the alphanumeric keyboard
KEY_A = 'a'A key
KEY_B = 'b'B key
KEY_C = 'c'C key
KEY_D = 'd'D key
KEY_E = 'e'E key
KEY_F = 'f'F key
KEY_G = 'g'G key
KEY_H = 'h'H key
KEY_I = 'i'I key
KEY_J = 'j'J key
KEY_K = 'k'K key
KEY_L = 'l'L key
KEY_M = 'm'M key
KEY_N = 'n'N key
KEY_O = 'o'O key
KEY_P = 'p'P key
KEY_Q = 'q'Q key
KEY_R = 'r'R key
KEY_S = 's'S key
KEY_T = 't'T key
KEY_U = 'u'U key
KEY_V = 'v'V key
KEY_W = 'w'W key
KEY_X = 'x'X key
KEY_Y = 'y'Y key
KEY_Z = 'z'Z key
KEY_BACK_QUOTE = '`'Back quote key
KEY_MINUS = '-'Minus key
KEY_EQUALS = '='Equals key
KEY_LEFT_BRACKET = '['Left square bracket key
KEY_RIGHT_BRACKET = ']'Right square bracket key
KEY_BACK_SLASH = '\\'Back slash key
KEY_SEMICOLON = ';'Semicolon key
KEY_QUOTE = '\''Quote key
KEY_COMMA = ','Comma key
KEY_DOT = '.'Dot key
KEY_SLASH = '/'Slash key
KEY_SPACE = ' 'Space key
KEY_CARET = '^'Caret key
KEY_PLUS = '+'Plus key
KEY_HASH = '#'Hash key
KEY_LESS = '<'Less than key
KEY_GREATER = '>'Greater than key
KEY_LEFT_PAREN = '('Left parenthesis key
KEY_RIGHT_PAREN = ')'Right parenthesis key
KEY_DOLLAR = '$'Dollar key
KEY_ASTERISK = '*'Asterisk key
KEY_COLON = ':'Colon key
KEY_EXCLAIM = '!'Exclamation mark key
KEY_DOUBLE_QUOTE = '"'Double quote key
KEY_PERCENT = '%'Percent key
KEY_AMPERSAND = '&'Ampersand key
KEY_QUESTION = '?'Question key
KEY_AT = '@'At key
KEY_UNDERSCORE = '_'Underscore key
KEY_ESC = 256Escape key
KEY_BACKSPACE = 257Backspace key
KEY_TAB = 258Tab key
KEY_RETURN = 259Return key
KEY_LEFT_SHIFT = 260
KEY_RIGHT_SHIFT = 261
KEY_LEFT_CTRL = 262
KEY_LEFT_CMD = 263
KEY_LEFT_ALT = 264
KEY_RIGHT_ALT = 265
KEY_RIGHT_CMD = 266
KEY_RIGHT_CTRL = 267
KEY_INSERT = 268Insert key
KEY_HOME = 269Home key
KEY_PGUP = 270Page Up key
KEY_DELETE = 271Delete
KEY_END = 272End key
KEY_PGDOWN = 273Page down
KEY_UP = 274Up arrow key
KEY_LEFT = 275Left arrow key
KEY_DOWN = 276Down arrow key
KEY_RIGHT = 277Right arrow key
KEY_PRINTSCREEN = 278
KEY_SCROLL_LOCK = 279
KEY_CAPS_LOCK = 280
KEY_NUM_LOCK = 281
KEY_PAUSE = 282
KEY_MENU = 283
KEY_NUMPAD_DIGIT_0 = 284
KEY_NUMPAD_DIGIT_1 = 285
KEY_NUMPAD_DIGIT_2 = 286
KEY_NUMPAD_DIGIT_3 = 287
KEY_NUMPAD_DIGIT_4 = 288
KEY_NUMPAD_DIGIT_5 = 289
KEY_NUMPAD_DIGIT_6 = 290
KEY_NUMPAD_DIGIT_7 = 291
KEY_NUMPAD_DIGIT_8 = 292
KEY_NUMPAD_DIGIT_9 = 293
KEY_NUMPAD_DIVIDE = 294
KEY_NUMPAD_MULTIPLY = 295
KEY_NUMPAD_MINUS = 296
KEY_NUMPAD_PLUS = 297
KEY_NUMPAD_RETURN = 298
KEY_NUMPAD_DOT = 299
KEY_NUMPAD_HOME = 300
KEY_NUMPAD_END = 301
KEY_NUMPAD_PGUP = 302
KEY_NUMPAD_PGDOWN = 303
KEY_NUMPAD_INSERT = 304
KEY_NUMPAD_DELETE = 305
KEY_NUMPAD_UP = 306
KEY_NUMPAD_LEFT = 307
KEY_NUMPAD_DOWN = 308
KEY_NUMPAD_RIGHT = 309
KEY_ESZETT = 310
KEY_U_UMLAUT = 311
KEY_O_UMLAUT = 312
KEY_A_UMLAUT = 313
KEY_ACUTE_ACCENT = 314
KEY_U_WITH_GRAVE = 315
KEY_SUPERSCRIPT_TWO = 316
KEY_F1 = 317F1 key
KEY_F2 = 318F2 key
KEY_F3 = 319F3 key
KEY_F4 = 320F4 key
KEY_F5 = 321F5 key
KEY_F6 = 322F6 key
KEY_F7 = 323F7 key
KEY_F8 = 324F8 key
KEY_F9 = 325F9 key
KEY_F10 = 326F10 key
KEY_F11 = 327F11 key
KEY_F12 = 328F12 key
KEY_ANY_SHIFT = 329
KEY_ANY_CTRL = 330
KEY_ANY_ALT = 331
KEY_ANY_CMD = 332
NUM_KEYS = 333The number of all keys

MOUSE_BUTTON#

NameDescription
MOUSE_BUTTON_UNKNOWN = 0
MOUSE_BUTTON_LEFT = 1Left mouse button
MOUSE_BUTTON_MIDDLE = 2Middle mouse button
MOUSE_BUTTON_RIGHT = 3Right mouse button
MOUSE_BUTTON_DCLICK = 4Left mouse button double click
MOUSE_BUTTON_AUX_0 = 5Auxiliary mouse button
MOUSE_BUTTON_AUX_1 = 6Auxiliary mouse button
MOUSE_BUTTON_AUX_2 = 7Auxiliary mouse button
MOUSE_BUTTON_AUX_3 = 8Auxiliary mouse button
MOUSE_NUM_BUTTONS = 9Number of mouse buttons

MOUSE_HANDLE#

NameDescription
MOUSE_HANDLE_GRAB = 0The mouse is grabbed when clicked (the cursor disappears and camera movement is controlled by the mouse).
MOUSE_HANDLE_SOFT = 1The mouse cursor disappears after being idle for a short time period.
MOUSE_HANDLE_USER = 2The mouse is not handled by the system (allows input handling by some custom module).

MOUSE_MASK#

NameDescription
MOUSE_MASK_LEFT = 1 << 0
MOUSE_MASK_MIDDLE = 1 << 1
MOUSE_MASK_RIGHT = 1 << 2
MOUSE_MASK_DCLICK = 1 << 3
MOUSE_MASK_AUX_0 = 1 << 4
MOUSE_MASK_AUX_1 = 1 << 5
MOUSE_MASK_AUX_2 = 1 << 6
MOUSE_MASK_AUX_3 = 1 << 7

CALLBACK_INDEX#

NameDescription
CALLBACK_MOUSE_DOWN = 0
CALLBACK_MOUSE_UP = 1
CALLBACK_MOUSE_AXES = 2
CALLBACK_MOUSE_MOTION = 3
CALLBACK_KEY_DOWN = 4
CALLBACK_KEY_PRESS = 5
CALLBACK_KEY_UP = 6
CALLBACK_CODE_DOWN = 7
CALLBACK_CODE_PRESS = 8
CALLBACK_CODE_UP = 9
CALLBACK_TEXT_PRESS = 10
CALLBACK_IMMEDIATE_INPUT = 11
NUM_CALLBACKS = 12

CODE#

NameDescription
CODE_UNKNOWN = 0
CODE_ESC = 1
CODE_F1 = 2
CODE_F2 = 3
CODE_F3 = 4
CODE_F4 = 5
CODE_F5 = 6
CODE_F6 = 7
CODE_F7 = 8
CODE_F8 = 9
CODE_F9 = 10
CODE_F10 = 11
CODE_F11 = 12
CODE_F12 = 13
CODE_PRINTSCREEN = 14
CODE_SCROLL_LOCK = 15
CODE_PAUSE = 16
CODE_BACK_QUOTE = 17
CODE_DIGIT_1 = 18
CODE_DIGIT_2 = 19
CODE_DIGIT_3 = 20
CODE_DIGIT_4 = 21
CODE_DIGIT_5 = 22
CODE_DIGIT_6 = 23
CODE_DIGIT_7 = 24
CODE_DIGIT_8 = 25
CODE_DIGIT_9 = 26
CODE_DIGIT_0 = 27
CODE_MINUS = 28
CODE_EQUALS = 29
CODE_BACKSPACE = 30
CODE_TAB = 31
CODE_Q = 32
CODE_W = 33
CODE_E = 34
CODE_R = 35
CODE_T = 36
CODE_Y = 37
CODE_U = 38
CODE_I = 39
CODE_O = 40
CODE_P = 41
CODE_LEFT_BRACKET = 42
CODE_RIGHT_BRACKET = 43
CODE_RETURN = 44
CODE_CAPS_LOCK = 45
CODE_A = 46
CODE_S = 47
CODE_D = 48
CODE_F = 49
CODE_G = 50
CODE_H = 51
CODE_J = 52
CODE_K = 53
CODE_L = 54
CODE_SEMICOLON = 55
CODE_QUOTE = 56
CODE_BACK_SLASH = 57
CODE_LEFT_SHIFT = 58
CODE_Z = 59
CODE_X = 60
CODE_C = 61
CODE_V = 62
CODE_B = 63
CODE_N = 64
CODE_M = 65
CODE_COMMA = 66
CODE_DOT = 67
CODE_SLASH = 68
CODE_RIGHT_SHIFT = 69
CODE_LEFT_CTRL = 70
CODE_LEFT_CMD = 71
CODE_LEFT_ALT = 72
CODE_SPACE = 73
CODE_RIGHT_ALT = 74
CODE_RIGHT_CMD = 75
CODE_MENU = 76
CODE_RIGHT_CTRL = 77
CODE_INSERT = 78
CODE_DELETE = 79
CODE_HOME = 80
CODE_END = 81
CODE_PGUP = 82
CODE_PGDOWN = 83
CODE_UP = 84
CODE_LEFT = 85
CODE_DOWN = 86
CODE_RIGHT = 87
CODE_NUM_LOCK = 88
CODE_NUMPAD_DIVIDE = 89
CODE_NUMPAD_MULTIPLY = 90
CODE_NUMPAD_MINUS = 91
CODE_NUMPAD_DIGIT_7 = 92
CODE_NUMPAD_DIGIT_8 = 93
CODE_NUMPAD_DIGIT_9 = 94
CODE_NUMPAD_PLUS = 95
CODE_NUMPAD_DIGIT_4 = 96
CODE_NUMPAD_DIGIT_5 = 97
CODE_NUMPAD_DIGIT_6 = 98
CODE_NUMPAD_DIGIT_1 = 99
CODE_NUMPAD_DIGIT_2 = 100
CODE_NUMPAD_DIGIT_3 = 101
CODE_NUMPAD_RETURN = 102
CODE_NUMPAD_DIGIT_0 = 103
CODE_NUMPAD_DOT = 104
NUM_CODES = 105

MOUSE_AXES#

NameDescription
MOUSE_AXIS_UNKNOWN = 0
MOUSE_AXIS_X = 1
MOUSE_AXIS_Y = 2
NUM_MOUSE_AXES = 3

Members


Math::ivec2 getMouseCoord ( ) const#

Returns a vector containing integer values of mouse pointer position.

Return value

Integer mouse pointer position.

Math::ivec2 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 ( ) const#

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 getMouseWheelHorizontal ( ) const#

Returns the current horizontal mouse scroll value.

Return value

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

int getCountGamePads ( ) const#

Returns the number of all game pads.

Return value

Number of all game pads.

Ptr<InputGamePad> getGamePad ( int num ) const#

Returns a game pad of the given index.

Arguments

  • int num - index.

Return value

InputGamepad object.

int getCountActiveGamePads ( ) const#

Returns the number of active game pads.

Return value

Number of active game pads.

Ptr<InputGamePad> getActiveGamePad ( int num ) const#

Returns an active game pad of the given index.

Arguments

  • int num - index.

Return value

InputGamePad object.

bool isKeyPressed ( Input::KEY key ) const#

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

Arguments

Return value

1 if the key is pressed; otherwise, 0.

bool isKeyDown ( Input::KEY key ) const#

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

bool isKeyUp ( Input::KEY key ) const#

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

bool isMouseButtonPressed ( Input::MOUSE_BUTTON button ) const#

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

bool isMouseButtonDown ( Input::MOUSE_BUTTON button ) const#

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

bool isMouseButtonUp ( Input::MOUSE_BUTTON button ) const#

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::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 setMouseHandle ( Input::MOUSE_HANDLE handle ) #

Sets the mouse behavior mode.

Arguments

Input::MOUSE_HANDLE getMouseHandle ( ) const#

Returns the mouse behavior mode.

Return value

Mouse behavior mode, one of the MOUSE_HANDLE_* values.

bool isCodePressed ( Input::CODE code ) const#

Arguments

bool isCodeDown ( Input::CODE code ) const#

Arguments

bool isCodeUp ( Input::CODE code ) const#

Arguments

Ptr<InputEventKeyboard> getCodeEvent ( Input::CODE code ) const#

Arguments

Input::CODE getLastCodeDown ( ) const#

Input::CODE getLastCodePressed ( ) const#

Input::CODE getLastCodeUp ( ) const#

const char * getCodeName ( Input::CODE code ) const#

Arguments

Input::CODE getCodeByName ( const char * name ) const#

Arguments

  • const char * name

Ptr<InputEventKeyboard> getKeyEvent ( Input::KEY code ) const#

Arguments

Input::KEY getLastKeyDown ( ) const#

Input::KEY getLastKeyPressed ( ) const#

Input::KEY getLastKeyUp ( ) const#

const char * getKeyName ( Input::KEY key ) const#

Arguments

Input::KEY getKeyByName ( const char * name ) const#

Arguments

  • const char * name

Ptr<InputEventMouseButton> getMouseButtonEvent ( Input::MOUSE_BUTTON button ) const#

Arguments

Input::MOUSE_BUTTON getLastMouseButtonDown ( ) const#

Input::MOUSE_BUTTON getLastMouseButtonPressed ( ) const#

Input::MOUSE_BUTTON getLastMouseButtonUp ( ) const#

Math::ivec2 getMouseFrameCoord ( ) const#

const char * getMouseButtonName ( Input::MOUSE_BUTTON button ) const#

Arguments

Input::MOUSE_BUTTON getMouseButtonByName ( const char * name ) const#

Arguments

  • const char * name

const char * getMouseAxisName ( Input::MOUSE_AXES axis ) const#

Arguments

Input::MOUSE_AXES getMouseAxisByName ( const char * name ) const#

Arguments

  • const char * name

int getEventsBuffer ( Vector<Ptr<InputEvent>> & events ) const#

Arguments

void sendUserEvent ( const Ptr<InputEvent> & e ) #

Arguments

bool getSysCode ( Input::CODE code ) const#

Arguments

bool getAndClearSysCode ( Input::CODE code ) #

Arguments

void forceSetSysCode ( Input::CODE code, bool value ) #

Arguments

bool getSysKey ( Input::KEY key ) const#

Arguments

bool getAndClearSysKey ( Input::KEY key ) #

Arguments

void forceSetSysKey ( Input::KEY key, bool value ) #

Arguments

int getSysMouseButtonsMask ( ) const#

void setSysMouseButtonsMask ( int mask ) #

Arguments

  • int mask

bool getSysMouseAxis ( Input::MOUSE_AXES axis ) const#

Arguments

bool getAndClearSysMouseAxis ( Input::MOUSE_AXES axis ) #

Arguments

void forceSetSysMouseAxis ( Input::MOUSE_AXES axis, int value ) #

Arguments

Last update: 2022-07-01
Build: ()