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

Captures keyboard inputs from the user. More...

#include <Keyboard.h>

Public Types

enum class  Key {
  Unknown = -1 , A = 0 , B , C ,
  D , E , F , G ,
  H , I , J , K ,
  L , M , N , O ,
  P , Q , R , S ,
  T , U , V , W ,
  X , Y , Z , Num0 ,
  Num1 , Num2 , Num3 , Num4 ,
  Num5 , Num6 , Num7 , Num8 ,
  Num9 , Escape , LControl , LShift ,
  LAlt , LSystem , RControl , RShift ,
  RAlt , RSystem , Menu , LBracket ,
  RBracket , Semicolon , Comma , Period ,
  Quote , Slash , Backslash , Tilde ,
  Equal , Hyphen , Space , Enter ,
  Backspace , Tab , PageUp , PageDown ,
  End , Home , Insert , Delete ,
  Add , Subtract , Multiply , Divide ,
  Left , Right , Up , Down ,
  Numpad0 , Numpad1 , Numpad2 , Numpad3 ,
  Numpad4 , Numpad5 , Numpad6 , Numpad7 ,
  Numpad8 , Numpad9 , F1 , F2 ,
  F3 , F4 , F5 , F6 ,
  F7 , F8 , F9 , F10 ,
  F11 , F12 , F13 , F14 ,
  F15 , Pause , KeyCount
}
 keyboard key codes More...
 

Public Member Functions

 Keyboard ()
 Default constructor. More...
 
void setEnable (bool enable)
 Enable or disable the keyboard. More...
 
bool isEnabled () const
 Check if the keyboard is enabled or not. More...
 
int onKeyUp (Callback< Key > callback)
 Add an event listener to a key up event. More...
 
int onKeyDown (Callback< Key > callback)
 Add an event listener to a key down event. More...
 
int onKeyHeld (Callback< Key > callback)
 Add an event listener to a key held event. More...
 
void suspend (bool suspend, KeyboardEvent event, int id)
 Suspend an event listener. More...
 
bool unsubscribe (KeyboardEvent event, int id)
 Remove an event listener from a key down or key up event. More...
 
void handleEvent (Event event)
 

Static Public Member Functions

static std::string keyToString (Key key)
 Convert an enum Key value to its string representation. More...
 
static Key stringToKey (const std::string &key)
 Convert a string representation of a key to its enum value. More...
 
static bool isKeyPressed (Key key)
 Check if a key is pressed or not. More...
 

Detailed Description

Captures keyboard inputs from the user.

This class is not meant to be instantiated directly, use ime::Scene::getInput or ime::Engine::getInputManager

Definition at line 51 of file Keyboard.h.

Member Enumeration Documentation

◆ Key

enum class ime::input::Keyboard::Key
strong

keyboard key codes

Enumerator
Unknown 

Unhandled key.

The A key.

The B key.

The C key.

The D key.

The E key.

The F key.

The G key.

The H key.

The I key.

The J key.

The K key.

The L key.

The M key.

The N key.

The O key.

The P key.

The Q key.

The R key.

The S key.

The T key.

The U key.

The V key.

The W key.

The X key.

The Y key.

The Z key.

Num0 

The 0 key.

Num1 

The 1 key.

Num2 

The 2 key.

Num3 

The 3 key.

Num4 

The 4 key.

Num5 

The 5 key.

Num6 

The 6 key.

Num7 

The 7 key.

Num8 

The 8 key.

Num9 

The 9 key.

Escape 

The Escape key.

LControl 

The left Control key.

LShift 

The left Shift key.

LAlt 

The left Alt key.

LSystem 

The left OS specific key: window (Windows and Linux), apple (MacOS X), ...

RControl 

The right Control key.

RShift 

The right Shift key.

RAlt 

The right Alt key.

RSystem 

The right OS specific key: window (Windows and Linux), apple (MacOS X), ...

Menu 

The Menu key.

LBracket 

The [ key.

RBracket 

The ] key.

Semicolon 

The ; key.

Comma 

The , key.

Period 

The . key.

Quote 

The ' key.

Slash 

The / key.

Backslash 

The \ key.

Tilde 

The ~ key.

Equal 

The = key.

Hyphen 

The - key (hyphen)

Space 

The Space key.

Enter 

The Enter/Return keys.

Backspace 

The Backspace key.

Tab 

The Tabulation key.

PageUp 

The Page up key.

PageDown 

The Page down key.

End 

The End key.

Home 

The Home key.

Insert 

The Insert key.

Delete 

The Delete key.

Add 

The + key.

Subtract 

The - key (minus, usually from numpad)

Multiply 

The * key.

Divide 

The / key.

Left 

Left arrow.

Right 

Right arrow.

Up 

Up arrow.

Down 

Down arrow.

Numpad0 

The numpad 0 key.

Numpad1 

The numpad 1 key.

Numpad2 

The numpad 2 key.

Numpad3 

The numpad 3 key.

Numpad4 

The numpad 4 key.

Numpad5 

The numpad 5 key.

Numpad6 

The numpad 6 key.

Numpad7 

The numpad 7 key.

Numpad8 

The numpad 8 key.

Numpad9 

The numpad 9 key.

F1 

The F1 key.

F2 

The F2 key.

F3 

The F3 key.

F4 

The F4 key.

F5 

The F5 key.

F6 

The F6 key.

F7 

The F7 key.

F8 

The F8 key.

F9 

The F9 key.

F10 

The F10 key.

F11 

The F11 key.

F12 

The F12 key.

F13 

The F13 key.

F14 

The F14 key.

F15 

The F15 key.

Pause 

The Pause key.

KeyCount 

Keep last – the total number of keyboard keys.

Definition at line 56 of file Keyboard.h.

Constructor & Destructor Documentation

◆ Keyboard()

ime::input::Keyboard::Keyboard ( )

Default constructor.

Member Function Documentation

◆ isEnabled()

bool ime::input::Keyboard::isEnabled ( ) const

Check if the keyboard is enabled or not.

Returns
True if enabled, otherwise false
See also
setEnabled

◆ isKeyPressed()

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

Check if a key is pressed or not.

Parameters
keyKey to be checked
Returns
True if the key is pressed or false if it not pressed

This function checks the state of a key in real time, unlike all the other function which are event-based

◆ keyToString()

static std::string ime::input::Keyboard::keyToString ( Key  key)
static

Convert an enum Key value to its string representation.

Parameters
keyThe key to be converted
Returns
The given key as a string

The returned string is the same as the enum value, that is, if key is Key::Space then the function will return "Space"

◆ onKeyDown()

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

Add an event listener to a key down event.

Parameters
callbackFunction to be executed when the 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::Keyboard::onKeyHeld ( Callback< 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::Keyboard::onKeyUp ( Callback< Key callback)

Add an event listener to a key up event.

Parameters
callbackFunction to be executed when a 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

◆ setEnable()

void ime::input::Keyboard::setEnable ( bool  enable)

Enable or disable the keyboard.

Parameters
enableTrue to enabled or false to disable

When disabled, the keyboard will no longer generate key up, down and held events

By default the keyboard is enabled

See also
isEnabled

◆ stringToKey()

static Key ime::input::Keyboard::stringToKey ( const std::string &  key)
static

Convert a string representation of a key to its enum value.

Parameters
keyThe key to be converted
Returns
The given key as an enum key value

The returned enum key value is the same as the string value, that is, if key is "Space" then the function will return Key::Space

Warning
If the given string is not convertible to an enum key value, them the program will exit with an error

◆ suspend()

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

Suspend an event listener.

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

◆ unsubscribe()

bool ime::input::Keyboard::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

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