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

 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...
 
JoystickgetJoystick (unsigned int index)
 Get a joystick. More...
 
const JoystickgetJoystick (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ InputManager()

ime::input::InputManager::InputManager ( )

Default constructor.

Member Function Documentation

◆ bindKey()

int ime::input::InputManager::bindKey ( Keyboard::Key  key,
KeyBindType  type,
const KeybindAction action 
)

Bind a key to an action.

Parameters
keyThe key to bind the action to
typeThe type of key bind
actionThe action to be performed when the key is triggered
Returns
The actions unique identifier
See also
unbindKey

◆ bindKeys()

int ime::input::InputManager::bindKeys ( Keyboard::Key  keyA,
Keyboard::Key  keyB,
KeyBindType  keyBindType,
const KeybindAction action 
)

Bind a two key combination to an action.

Parameters
keyAThe first key
keyBThe second key
keyBindTypeThe type of key bind (key down or key held only)
actionThe action to be performed when the two keys are triggered
Returns
The actions unique identifier

Note that if keyBindType is ime::input::KeyBindType::KeyUp, the key bind will be ignored

See also
bindKey, unbindKey

◆ getJoystick()

Joystick & ime::input::InputManager::getJoystick ( unsigned int  index)

Get a joystick.

Parameters
indexThe index of the joystick in range [0, ime::Joystick::Count - 1]
Returns
The joystick with the specified index
Exceptions
ime::InvalidArgumentif the specified index is out of bounds

◆ isAllInputDisabled()

bool ime::input::InputManager::isAllInputDisabled ( ) const

Check if all the inputs are disabled.

Returns
True if all the inputs are disabled or false if at least one input is enabled
See also
setAllInputEnable, isAllInputEnabled

◆ isAllInputEnabled()

bool ime::input::InputManager::isAllInputEnabled ( ) const

Check if all input is enabled or not.

Returns
True if all the inputs are enabled, or false if at least one input is disabled
See also
setAllInputEnable, isAllInputDisabled

◆ isInputEnabled()

bool ime::input::InputManager::isInputEnabled ( InputType  inputType) const

Check if an input is enabled or not.

Parameters
inputTypeThe type of input to be checked
Returns
True if enabled, otherwise false
See also
setEnabled, setEnableAll

◆ 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

◆ onJoyAxisMove()

int ime::input::InputManager::onJoyAxisMove ( const Callback< unsigned int, Joystick::Axis, float > &  callback)

Add an event listener to an joystick axis move event.

Parameters
callbackThe function to be executed when the axis of a joystick is moved
Returns
The event listeners identification number

The callback is passed the index of the joystick whose axis was moved, the axis tha was moved and its new position respectively

◆ onJoyButtonPress()

int ime::input::InputManager::onJoyButtonPress ( const Callback< unsigned int, unsigned int > &  callback)

Add an event listener to a joystick button press event.

Parameters
callbackThe function to be executed when a joystick button is pressed
Returns
The event listeners identification number

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

◆ onJoyButtonRelease()

int ime::input::InputManager::onJoyButtonRelease ( const Callback< unsigned int, unsigned int > &  callback)

Add an event listener to joystick button release event.

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

The callback is passed the index of the joystick the button was released and the button that was released respectively

◆ onJoyConnect()

int ime::input::InputManager::onJoyConnect ( const Callback< unsigned int > &  callback)

Add an event listener to a joystick connection event.

Parameters
callbackFunction to be executed when a joystick is connected
Returns
The event listeners identification number

The callback is passed the index of the joystick on invocation

◆ onJoyDisconnect()

int ime::input::InputManager::onJoyDisconnect ( const Callback< unsigned int > &  callback)

Add an event listener to a joystick disconnect event.

Parameters
callbackFunction to be executed when a joystick is disconnected
Returns
The event listeners identification number

The callback is passed the index of the joystick on invocation

◆ 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

◆ setAllInputEnable()

void ime::input::InputManager::setAllInputEnable ( bool  enable)

Enable or disable all input.

Parameters
enableTrue to enable or false to disable

By default all the inputs are enabled

See also
setEnable, isEnable, isAllInputEnabled, isAllInputDisabled

◆ setInputEnable()

void ime::input::InputManager::setInputEnable ( InputType  inputType,
bool  enable 
)

Enable or disable an input.

Parameters
inputTypeThe input to be enabled or disabled
enableTrue to enabled or false to disable

When disabled, the specified input will no longer generate input events

By default all the inputs are enabled

See also
isEnabled, setEnableAll

◆ suspend()

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

Suspend an event listener from a keyboard event.

Parameters
suspendTrue to suspend the listener or false to unsuspend it
eventThe event the listener is registered to
idThe 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

◆ unbindKey()

bool ime::input::InputManager::unbindKey ( KeyBindType  keyBindType,
int  id 
)

Unbind a key action.

Parameters
keyBindTypeThe type of key action to unbind
idThe id of the action
Returns
True if the action was unbounded or false if no such binding key exists
See also
bindKey

◆ unsubscribe() [1/3]

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

Remove an event listener from a joystick event.

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

◆ unsubscribe() [2/3]

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() [3/3]

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: