JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Key.hpp
Go to the documentation of this file.
1// Copyright 2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "input.hpp"
8
9#include <optional>
10#include <string>
11#include <string_view>
12#include <variant>
13#include <vector>
14
15namespace jngl {
16
36class Key {
37public:
39 Key(key::KeyType); // NOLINT
40
44 Key(char character); // NOLINT
45
50 explicit Key(std::string character);
51
56
59
61 bool down() const;
62
65 bool pressed() const;
66
67 bool operator==(const Key&) const = default;
68
69private:
72};
73
80
81} // namespace jngl
A key on the keyboard: one without a character, e.g.
Definition Key.hpp:36
static std::optional< Key > fromString(std::string_view name)
The key whose toString() is name, or std::nullopt if there's none.
std::string toString() const
Used to display the key, e.g.
Key(std::string character)
The key that types character, which has to be exactly one UTF-8 character, e.g.
bool down() const
Whether the key is down, regardless of Shift, Ctrl and Alt.
Key(char character)
The key that types character, e.g.
Key(key::KeyType)
A key without a character, e.g. jngl::key::F1, or key::Ctrl for either of the two.
bool pressed() const
Whether the key has been pressed since the next to last call to updateInput(), regardless of Shift,...
Input related functions.
KeyType
Keyboard keys.
Definition input.hpp:26
JNGL's main namespace.
std::vector< Key > keysPressed()
The keys that have been pressed since the next to last call to updateInput(), in the order they went ...