Manages keyboard and mouse inputs. More...
#include <InputManager.h>
Public Member Functions | |
InputManager () | |
Default constructor. More... | |
void | setInputEnable (InputType inputType, bool enable) |
Enable or disable an input. More... | |
bool | isInputEnabled (InputType inputType) const |
Check if an input is enabled or not. More... | |
void | setAllInputEnable (bool enable) |
Enable or disable all input. More... | |
bool | isAllInputEnabled () const |
Check if all input is enabled or not. More... | |
bool | isAllInputDisabled () const |
Check if all the inputs are disabled. More... | |
int | bindKey (Keyboard::Key key, KeyBindType type, const KeybindAction &action) |
Bind a key to an action. More... | |
int | bindKeys (Keyboard::Key keyA, Keyboard::Key keyB, KeyBindType keyBindType, const KeybindAction &action) |
Bind a two key combination to an action. More... | |
bool | unbindKey (KeyBindType keyBindType, int id) |
Unbind a key action. More... | |
int | onKeyUp (Callback< Keyboard::Key > callback) |
Add an event listener to a key up event. More... | |
int | onKeyDown (Callback< Keyboard::Key > callback) |
Add an event listener to a key down event. More... | |
int | onKeyHeld (Callback< Keyboard::Key > callback) |
Add an event listener to a key held event. More... | |
bool | unsubscribe (KeyboardEvent event, int id) |
Remove an event listener from a key down or key up event. More... | |
void | suspend (bool suspend, KeyboardEvent event, int id) |
Suspend an event listener from a keyboard event. More... | |
int | onMouseUp (Callback< Mouse::Button, int, int > callback) |
Add an event listener to a mouse button up event. More... | |
int | onMouseUp (Callback< Mouse::Button > callback) |
Add an event listener to a mouse button up event. More... | |
int | onMouseDown (Callback< Mouse::Button, int, int > callback) |
Add an event listener to a mouse button up event. More... | |
int | onMouseDown (Callback< Mouse::Button > callback) |
Add an event listener to a mouse button down event. More... | |
int | onMouseMove (Callback< int, int > callback) |
Add an event listener to a mouse move event. More... | |
int | onMouseWheelScroll (Callback< Mouse::Wheel, float, int, int > callback) |
Add an event listener to a mouse wheel scroll event. More... | |
bool | unsubscribe (MouseEvent event, int id) |
Remove an event listener from a mouse event. More... | |
int | onJoyConnect (const Callback< unsigned int > &callback) |
Add an event listener to a joystick connection event. More... | |
int | onJoyDisconnect (const Callback< unsigned int > &callback) |
Add an event listener to a joystick disconnect event. More... | |
int | onJoyButtonPress (const Callback< unsigned int, unsigned int > &callback) |
Add an event listener to a joystick button press event. More... | |
int | onJoyButtonRelease (const Callback< unsigned int, unsigned int > &callback) |
Add an event listener to joystick button release event. More... | |
int | onJoyAxisMove (const Callback< unsigned int, Joystick::Axis, float > &callback) |
Add an event listener to an joystick axis move event. More... | |
Joystick & | getJoystick (unsigned int index) |
Get a joystick. More... | |
const Joystick & | getJoystick (unsigned int index) const |
bool | unsubscribe (JoystickEvent event, int id) |
Remove an event listener from a joystick event. More... | |
void | handleEvent (Event event) |
void | update () |
Static Public Member Functions | |
static bool | isKeyPressed (Keyboard::Key key) |
Check if a key is currently pressed or not. More... | |
static bool | isMouseDown (Mouse::Button button) |
Check if a mouse button is currently pressed or not. More... | |
Manages keyboard and mouse inputs.
This class is not meant to be instantiated directly, use ime::Scene::getInput or ime::Engine::getInputManager
Definition at line 62 of file InputManager.h.
ime::input::InputManager::InputManager | ( | ) |
Default constructor.
int ime::input::InputManager::bindKey | ( | Keyboard::Key | key, |
KeyBindType | type, | ||
const KeybindAction & | action | ||
) |
Bind a key to an action.
key | The key to bind the action to |
type | The type of key bind |
action | The action to be performed when the key is triggered |
int ime::input::InputManager::bindKeys | ( | Keyboard::Key | keyA, |
Keyboard::Key | keyB, | ||
KeyBindType | keyBindType, | ||
const KeybindAction & | action | ||
) |
Bind a two key combination to an action.
keyA | The first key |
keyB | The second key |
keyBindType | The type of key bind (key down or key held only) |
action | The action to be performed when the two keys are triggered |
Note that if keyBindType is ime::input::KeyBindType::KeyUp, the key bind will be ignored
Joystick & ime::input::InputManager::getJoystick | ( | unsigned int | index | ) |
Get a joystick.
index | The index of the joystick in range [0, ime::Joystick::Count - 1] |
ime::InvalidArgument | if the specified index is out of bounds |
bool ime::input::InputManager::isAllInputDisabled | ( | ) | const |
Check if all the inputs are disabled.
bool ime::input::InputManager::isAllInputEnabled | ( | ) | const |
Check if all input is enabled or not.
bool ime::input::InputManager::isInputEnabled | ( | InputType | inputType | ) | const |
Check if an input is enabled or not.
inputType | The type of input to be checked |
|
static |
Check if a key is currently pressed or not.
key | Key to be checked |
This function checks the state of the key in real time
|
static |
Check if a mouse button is currently pressed or not.
button | Mouse button to check |
This function checks the state of a mouse button in real time
int ime::input::InputManager::onJoyAxisMove | ( | const Callback< unsigned int, Joystick::Axis, float > & | callback | ) |
Add an event listener to an joystick axis move event.
callback | The function to be executed when the axis of a joystick is moved |
The callback is passed the index of the joystick whose axis was moved, the axis tha was moved and its new position respectively
int ime::input::InputManager::onJoyButtonPress | ( | const Callback< unsigned int, unsigned int > & | callback | ) |
Add an event listener to a joystick button press event.
callback | The function to be executed when a joystick button is pressed |
A button press event does not fire while the button is held down
The callback is passed the index of the pressed joystick and the button that was pressed respectively
int ime::input::InputManager::onJoyButtonRelease | ( | const Callback< unsigned int, unsigned int > & | callback | ) |
Add an event listener to joystick button release event.
callback | The function to be executed when a joystick button is released |
The callback is passed the index of the joystick the button was released and the button that was released respectively
int ime::input::InputManager::onJoyConnect | ( | const Callback< unsigned int > & | callback | ) |
Add an event listener to a joystick connection event.
callback | Function to be executed when a joystick is connected |
The callback is passed the index of the joystick on invocation
int ime::input::InputManager::onJoyDisconnect | ( | const Callback< unsigned int > & | callback | ) |
Add an event listener to a joystick disconnect event.
callback | Function to be executed when a joystick is disconnected |
The callback is passed the index of the joystick on invocation
int ime::input::InputManager::onKeyDown | ( | Callback< Keyboard::Key > | callback | ) |
Add an event listener to a key down event.
callback | Function to be executed when a key is down |
The key down event fires once when a key is depressed. If the key remains depressed a key held event fires. In other words, if you press and hold a key on the keyboard, the key down event will fire once and wil not fire again until the key is released and pressed again
int ime::input::InputManager::onKeyHeld | ( | Callback< Keyboard::Key > | callback | ) |
Add an event listener to a key held event.
callback | Function to be executed when a key is held |
The key held event will continue to fire while a key is held down. The event always fires after a key down event. The callback is passed the key that is held down
int ime::input::InputManager::onKeyUp | ( | Callback< Keyboard::Key > | callback | ) |
Add an event listener to a key up event.
callback | Function to be executed when the key is released |
This event is triggered only when a depressed/held key is released. The callback is passed the key that was released
int ime::input::InputManager::onMouseDown | ( | Callback< Mouse::Button > | callback | ) |
Add an event listener to a mouse button down event.
callback | The function to be executed when the mouse button is depressed |
The callback is passed the button that was depressed
int ime::input::InputManager::onMouseDown | ( | Callback< Mouse::Button, int, int > | callback | ) |
Add an event listener to a mouse button up event.
callback | The function to be executed when the event a mouse button is released |
The mouse button down event is fired when a mouse button is depressed. The callback is passed the button that was depressed and the coordinates of the mouse cursor when the button was depressed. The mouse cursor coordinates are relative to the game window
int ime::input::InputManager::onMouseMove | ( | Callback< int, int > | callback | ) |
Add an event listener to a mouse move event.
callback | Function to execute when the mouse moves |
The callback function will be passed the new position of the mouse cursor
int ime::input::InputManager::onMouseUp | ( | Callback< Mouse::Button > | callback | ) |
Add an event listener to a mouse button up event.
callback | The function to be executed when the mouse button is released |
The mouse button up event is fired when a depressed mouse button is released. The callback is passed the button that was released
int ime::input::InputManager::onMouseUp | ( | Callback< Mouse::Button, int, int > | callback | ) |
Add an event listener to a mouse button up event.
callback | The function to be executed when the mouse button is released |
The mouse button up event is fired when a depressed mouse button is released. The callback is passed the button that was released and the coordinates of the mouse cursor when the button was released. The mouse cursor coordinates are relative to the game window
int ime::input::InputManager::onMouseWheelScroll | ( | Callback< Mouse::Wheel, float, int, int > | callback | ) |
Add an event listener to a mouse wheel scroll event.
callback | Function to be executed when the mouse wheel is scrolled |
The callback is passed the scrolled wheel and the wheel offset (positive is up/left, negative is down/right), and the mouse coordinates relative to the game window
void ime::input::InputManager::setAllInputEnable | ( | bool | enable | ) |
Enable or disable all input.
enable | True to enable or false to disable |
By default all the inputs are enabled
void ime::input::InputManager::setInputEnable | ( | InputType | inputType, |
bool | enable | ||
) |
Enable or disable an input.
inputType | The input to be enabled or disabled |
enable | True to enabled or false to disable |
When disabled, the specified input will no longer generate input events
By default all the inputs are enabled
void ime::input::InputManager::suspend | ( | bool | suspend, |
KeyboardEvent | event, | ||
int | id | ||
) |
Suspend an event listener from a keyboard event.
suspend | True to suspend the listener or false to unsuspend it |
event | The event the listener is registered to |
id | The id number of the event listener to be suspended |
A suspended event listener is not invoked when the event it is listening for is fired
bool ime::input::InputManager::unbindKey | ( | KeyBindType | keyBindType, |
int | id | ||
) |
Unbind a key action.
keyBindType | The type of key action to unbind |
id | The id of the action |
bool ime::input::InputManager::unsubscribe | ( | JoystickEvent | event, |
int | id | ||
) |
Remove an event listener from a joystick event.
event | The event to remove the event listener from |
id | The event listeners identification number |
bool ime::input::InputManager::unsubscribe | ( | KeyboardEvent | event, |
int | id | ||
) |
Remove an event listener from a key down or key up event.
event | Event to remove event listener from |
id | Identification number of the listener to be removed |
bool ime::input::InputManager::unsubscribe | ( | MouseEvent | event, |
int | id | ||
) |
Remove an event listener from a mouse event.
event | The event to remove the event listener from |
id | The id of the event listener |