Unigine.Input Class
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:
void Update()
{
float move_speed = 1.0f;
float turn_speed = 5.0f;
if (Console.Activity)
return;
vec3 direction = node.GetWorldDirection(MathLib.AXIS.Y);
if (Input.IsKeyPressed(Input.KEY.UP) || Input.IsKeyPressed(Input.KEY.W))
{
node.WorldPosition += direction * move_speed * Engine.ifps;
}
if (Input.IsKeyPressed(Input.KEY.DOWN) || Input.IsKeyPressed(Input.KEY.S))
{
node.WorldPosition -= direction * move_speed * Engine.ifps;
}
if (Input.IsKeyPressed(Input.KEY.LEFT) || Input.IsKeyPressed(Input.KEY.A))
{
node.Rotate(0.0f, 0.0f, turn_speed * Engine.ifps);
}
if (Input.IsKeyPressed(Input.KEY.RIGHT) || Input.IsKeyPressed(Input.KEY.D))
{
node.Rotate(0.0f, 0.0f, -turn_speed * Engine.ifps);
}
}
Input Class
Enums
KEY#
MOUSE_BUTTON#
MOUSE_HANDLE#
Properties
int CountActiveGamePads#
The number of active game pads.
int CountGamePads#
The number of all game pads.
int MouseWheelHorizontal#
The horizontal mouse scroll value.
int MouseWheel#
The vertical mouse scroll value.
vec2 MouseDelta#
Vector containing delta values of the mouse cursor position.
ivec2 MouseCoordDelta#
Vector containing integer delta values of the mouse cursor position.
ivec2 MouseCoord#
Vector containing integer values of the mouse cursor position.
Input.MOUSE_HANDLE MouseHandle#
The mouse behavior mode, one of the MOUSE_HANDLE values.
set
Sets the mouse behavior mode.
set value -
Mouse behavior mode, one of the MOUSE_HANDLE values.
Members
InputGamePad GetGamePad ( int num ) #
Returns a game pad of the given index.Arguments
- int num - index.
Return value
InputGamepad object.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 Input.KEY enum values.
Return value
True if the key is pressed; otherwise, false.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.SPACE)) {
Log.Message("space key was pressed\n");
}
Arguments
- Input.KEY key - One of the Input.KEY enum values.
Return value
True during the first frame when the key was pressed, false 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 Input.KEY enum values.
Return value
True during the first frame when the key was released; otherwise, false.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 Input.MOUSE_BUTTON enum values.
Return value
True if the mouse button is pressed; otherwise, false.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 Input.MOUSE_BUTTON enum values.
Return value
True during the first frame when the mouse button was released; otherwise, false.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 Input.MOUSE_BUTTON enum values.
Return value
True during the first frame when the mouse button was released; otherwise, false.Last update:
2020-09-23
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)