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... | |
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.
|
strong |
keyboard key codes
Definition at line 56 of file Keyboard.h.
ime::input::Keyboard::Keyboard | ( | ) |
Default constructor.
bool ime::input::Keyboard::isEnabled | ( | ) | const |
Check if the keyboard is enabled or not.
|
static |
Check if a key is pressed or not.
key | Key to be checked |
This function checks the state of a key in real time, unlike all the other function which are event-based
|
static |
Convert an enum Key value to its string representation.
key | The key to be converted |
The returned string is the same as the enum value, that is, if key is Key::Space then the function will return "Space"
Add an event listener to a key down event.
callback | Function to be executed when the 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
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
Add an event listener to a key up event.
callback | Function to be executed when a key is released |
This event is triggered only when a depressed/held key is released. The callback is passed the key that was released
void ime::input::Keyboard::setEnable | ( | bool | enable | ) |
Enable or disable the keyboard.
enable | True 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
|
static |
Convert a string representation of a key to its enum value.
key | The key to be converted |
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
void ime::input::Keyboard::suspend | ( | bool | suspend, |
KeyboardEvent | event, | ||
int | id | ||
) |
Suspend an event listener.
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::Keyboard::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 |