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

Public Member Functions

 Keyboard ()
 Default constructor. 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...
 
bool unsubscribe (KeyboardEvent event, int id)
 Remove an event listener from a key down or key up event. More...
 
void handleEvent (Event event)
 Handle a system event. More...
 

Static Public Member Functions

static bool isKeyPressed (Key key)
 Check if a key is pressed or not. More...
 

Detailed Description

Captures keyboard inputs from the user.

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 52 of file Keyboard.h.

Member Enumeration Documentation

◆ Key

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 57 of file Keyboard.h.

Constructor & Destructor Documentation

◆ Keyboard()

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

Default constructor.

Member Function Documentation

◆ handleEvent()

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

Handle a system event.

Parameters
eventEvent to be handled

◆ 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

◆ 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

◆ 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: