|
JNGL
Easy to use cross-platform 2D game library
|
A key on the keyboard: one without a character, e.g. More...
#include <jngl/Key.hpp>
Public Member Functions | |
| Key (key::KeyType) | |
| A key without a character, e.g. jngl::key::F1, or key::Ctrl for either of the two. | |
| Key (char character) | |
The key that types character, e.g. | |
| Key (std::string character) | |
The key that types character, which has to be exactly one UTF-8 character, e.g. | |
| std::string | toString () const |
| Used to display the key, e.g. | |
| bool | down () const |
| Whether the key is down, regardless of Shift, Ctrl and Alt. | |
| bool | pressed () const |
| Whether the key has been pressed since the next to last call to updateInput(), regardless of Shift, Ctrl and Alt. | |
| bool | operator== (const Key &) const =default |
Static Public Member Functions | |
| static std::optional< Key > | fromString (std::string_view name) |
The key whose toString() is name, or std::nullopt if there's none. | |
A key on the keyboard: one without a character, e.g.
jngl::key::F1, or the one that types a character, e.g. Q or Ö
Unlike for jngl::keyDown(const std::string&), Shift doesn't matter: ‘jngl::Key('q’)is the same key asjngl::Key('Q')`. That makes it something to store, e.g. the key the user has chosen for an action, see toString() and jngl::keysPressed().
Example:
| Key | ( | char | character | ) |
The key that types character, e.g.
'q' (the same as 'Q'), or key::Space for ' '
| std::runtime_error | if character isn't ASCII |
|
explicit |
The key that types character, which has to be exactly one UTF-8 character, e.g.
"ö" (the same as "Ö"), or key::Space for " "
| std::runtime_error | if character isn't exactly one character |
| std::string toString | ( | ) | const |
Used to display the key, e.g.
"F1", "Space" or "Ö", which fromString() turns back into it
A key without a character gets jngl::keyToString(), one with a letter it in uppercase.