Public Member Functions | Static Public Member Functions | List of all members
ime::input::InputManager Class Reference

Manages keyboard and mouse inputs. More...

#include <InputManager.h>

Public Member Functions

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...
 
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...
 
void handleEvent (Event event)
 Update the event manager. More...
 

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

Detailed Description

Manages keyboard and mouse inputs.

You usually don't instantiate this class directly, you either use the input manager that is local to a Scene or the global input manager that from the Engine class

Definition at line 42 of file InputManager.h.

Member Function Documentation

◆ handleEvent()

void ime::input::InputManager::handleEvent ( Event  event)

Update the event manager.

Parameters
eventEvent to be handled

◆ isKeyPressed()

static bool ime::input::InputManager::isKeyPressed ( Keyboard::Key  key)
static

Check if a key is currently pressed or not.

Parameters
keyKey to be checked
Returns
True if the key is pressed, otherwise false

This function checks the state of the key in real time

◆ isMouseDown()

static bool ime::input::InputManager::isMouseDown ( Mouse::Button  button)
static

Check if a mouse button is currently pressed or not.

Parameters
buttonMouse button to check
Returns
True if the mouse button is pressed, otherwise false

This function checks the state of a mouse button in real time

◆ onKeyDown()

int ime::input::InputManager::onKeyDown ( Callback< Keyboard::Key callback)

Add an event listener to a key down event.

Parameters
callbackFunction to be executed when a key is down
Returns
The event listeners identification number

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

See also
onKeyUp and onKeyHeld

◆ onKeyHeld()

int ime::input::InputManager::onKeyHeld ( Callback< Keyboard::Key callback)

Add an event listener to a key held event.

Parameters
callbackFunction to be executed when a key is held
Returns
The event listeners identification number

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

See also
onKeyDown

◆ onKeyUp()

int ime::input::InputManager::onKeyUp ( Callback< Keyboard::Key callback)

Add an event listener to a key up event.

Parameters
callbackFunction to be executed when the key is released
Returns
The event listeners identification number

This event is triggered only when a depressed/held key is released. The callback is passed the key that was released

See also
onKeyDown and onKeyHeld

◆ onMouseDown() [1/2]

int ime::input::InputManager::onMouseDown ( Callback< Mouse::Button callback)

Add an event listener to a mouse button down event.

Parameters
callbackThe function to be executed when the mouse button is depressed
Returns
The event listeners identification number

The callback is passed the button that was depressed

Note
This event does NOT fire repetitively while the mouse button is depressed

◆ onMouseDown() [2/2]

int ime::input::InputManager::onMouseDown ( Callback< Mouse::Button, int, int >  callback)

Add an event listener to a mouse button up event.

Parameters
callbackThe function to be executed when the event a mouse button is released
Returns
The event listeners identification number

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

Note
This event does NOT fire repetitively while the mouse button is depressed

◆ onMouseMove()

int ime::input::InputManager::onMouseMove ( Callback< int, int >  callback)

Add an event listener to a mouse move event.

Parameters
callbackFunction to execute when the mouse moves
Returns
The event listeners identification number

The callback function will be passed the new position of the mouse cursor

◆ onMouseUp() [1/2]

int ime::input::InputManager::onMouseUp ( Callback< Mouse::Button callback)

Add an event listener to a mouse button up event.

Parameters
callbackThe function to be executed when the mouse button is released
Returns
The event listeners identification number

The mouse button up event is fired when a depressed mouse button is released. The callback is passed the button that was released

◆ onMouseUp() [2/2]

int ime::input::InputManager::onMouseUp ( Callback< Mouse::Button, int, int >  callback)

Add an event listener to a mouse button up event.

Parameters
callbackThe function to be executed when the mouse button is released
Returns
The event listeners identification number

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

◆ onMouseWheelScroll()

int ime::input::InputManager::onMouseWheelScroll ( Callback< Mouse::Wheel, float, int, int >  callback)

Add an event listener to a mouse wheel scroll event.

Parameters
callbackFunction to be executed when the mouse wheel is scrolled
Returns
The event listeners identification number

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

◆ unsubscribe() [1/2]

bool ime::input::InputManager::unsubscribe ( KeyboardEvent  event,
int  id 
)

Remove an event listener from a key down or key up event.

Parameters
eventEvent to remove event listener from
idIdentification number of the listener to be removed
Returns
True if the event listener was removed from the event, or false if the specified event does not have an event listener with the specified id

◆ unsubscribe() [2/2]

bool ime::input::InputManager::unsubscribe ( MouseEvent  event,
int  id 
)

Remove an event listener from a mouse event.

Parameters
eventThe event to remove the event listener from
idThe id of the event listener
Returns
True if the event listener was removed or false if the given event does not have the specified event listener

The documentation for this class was generated from the following file: