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:
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#
MOUSE_BUTTON#
MOUSE_HANDLE#
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.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.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.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.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.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.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.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.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.void setMouseHandle ( Input::MOUSE_HANDLE handle ) #
Sets the mouse behavior mode.Arguments
- Input::MOUSE_HANDLE handle - Mouse behavior mode, one of the MOUSE_HANDLE_* values.
Input::MOUSE_HANDLE getMouseHandle ( ) #
Returns the mouse behavior mode.Return value
Mouse behavior mode, one of the MOUSE_HANDLE_* values.Last update:
2021-12-13
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)