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
FAQ
编程
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
应用程序接口
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
Rendering-Related Classes
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

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::getActivity())
			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_KEY_SPACE = ' 'Space key
KEY_EXCLAIM = '!'Exclamation mark key
KEY_DOUBLE_QUOTE = '"'Double quote key
KEY_HASH = '#'Hash key
KEY_DOLLAR = '$'Dollar key
KEY_PERCENT = '%'Percent key
KEY_AMPERSAND = '&'Ampersand key
KEY_QUOTE = '\''Quote key
KEY_APOSTROPHE = '\''Apostrophe key (KEY_APOSTROPHE = KEY_QUOTE)
KEY_LEFT_PAREN = '('Left parenthesis key
KEY_RIGHT_PAREN = ')'Right parenthesis key
KEY_ASTERISK = '*'Asterisk key
KEY_PLUS = '+'Plus key
KEY_COMMA = ','Comma key
KEY_MINUS = '-'Minus key
KEY_DOT = '.'Dot key
KEY_SLASH = '/'Slash key
KEY_COLON = ':'Colon key
KEY_SEMICOLON = ';'Semicolon key
KEY_LESS = '<'Less than key
KEY_EQUALS = '='Equals key
KEY_GREATER = '>'Greater than key
KEY_QUESTION = '?'Question key
KEY_AT = '@'At key
KEY_LEFT_BRACKET = '['Left square bracket key
KEY_BACK_SLASH = '\\'Back slash key
KEY_RIGHT_BRACKET = ']'Right square bracket key
KEY_CARET = '^'Caret key
KEY_UNDERSCORE = '_'Underscore key
KEY_BACK_QUOTE = '`'Back quote key
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_ESC = 256Escape key
KEY_TAB = 257Tab key
KEY_BACKSPACE = 258Backspace key
KEY_RETURN = 259Return key
KEY_DELETE = 260Delete
KEY_INSERT = 261Insert key
KEY_HOME = 262Home key
KEY_END = 263End key
KEY_PGUP = 264Page Up key
KEY_PGDOWN = 265Page down
KEY_LEFT = 266Left arrow key
KEY_RIGHT = 267Right arrow key
KEY_UP = 268Up arrow key
KEY_DOWN = 269Down arrow key
KEY_SHIFT = 270Shift key
KEY_CTRL = 271Control key
KEY_ALT = 272Alt key
KEY_CMD = 273Command key
KEY_SCROLL = 274Scroll lock key
KEY_CAPS = 275Caps lock key
KEY_NUM = 276Num lock key
KEY_F1 = 277F1 key
KEY_F2 = 278F2 key
KEY_F3 = 279F3 key
KEY_F4 = 280F4 key
KEY_F5 = 281F5 key
KEY_F6 = 282F6 key
KEY_F7 = 283F7 key
KEY_F8 = 284F8 key
KEY_F9 = 285F9 key
KEY_F10 = 286F10 key
KEY_F11 = 287F11 key
KEY_F12 = 288F12 key
NUM_KEYS = 289The number of all keys

MOUSE_BUTTON#

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

Members


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

Returns the current horizontal mouse scroll value.

Return value

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

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.

bool isKeyPressed ( Input::KEY 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::isKeyPressed(Input::KEY_RETURN)) {
	Log::message("enter key is held down\n");
}

Arguments

  • Input::KEY key - One of the preset KEY_ codes.

Return value

1 if the key is pressed; otherwise, 0.

bool isKeyDown ( Input::KEY 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::isKeyDown(Input::KEY_KEY_SPACE)) {
	Log::message("space key was pressed\n");
}

Arguments

  • Input::KEY 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.

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

Arguments

  • Input::KEY key - One of the preset KEY_ codes.

Return value

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

bool isMouseButtonPressed ( Input::MOUSE_BUTTON 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::isMouseButtonPressed(Input::MOUSE_BUTTON_LEFT)) {
	Log::message("left mouse button is held down\n");
}

Arguments

  • Input::MOUSE_BUTTON button - One of the preset MOUSE_BUTTON_ codes.

Return value

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

bool isMouseButtonDown ( Input::MOUSE_BUTTON 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::isMouseButtonDown(Input::MOUSE_BUTTON_LEFT)) {
	Log::message("left mouse button was pressed\n");
}

Arguments

  • Input::MOUSE_BUTTON button - One of the preset MOUSE_BUTTON_ codes.

Return value

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

bool isMouseButtonUp ( Input::MOUSE_BUTTON 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::isMouseButtonUp(Input::MOUSE_BUTTON_LEFT)) {
	Log::message("left mouse button was released\n");
}

Arguments

  • Input::MOUSE_BUTTON button - One of the preset MOUSE_BUTTON_ codes.

Return value

1 during the first frame when the mouse button was released; otherwise, 0.
Last update: 2020-02-20
Build: ()