Keyboard
micro::keyboard is an input device that tracks per-frame key state. Attach one
to a window and query it in your game loop.
Setup
micro::window win{"Input demo", 800, 600};
micro::keyboard kb{win};
win.run([&](float dt) {
if (kb.is_key_pressed(micro::key::space)) { player.jump(); }
if (kb.is_key_down(micro::key::right)) { player.move_right(dt); }
});
Querying key state
bool is_key_down (key k) const noexcept; // held this frame
bool is_key_up (key k) const noexcept; // not held this frame
bool is_key_pressed (key k) const noexcept; // just pressed (down now, was up last frame)
bool is_key_released(key k) const noexcept; // just released (up now, was down last frame)
Use is_key_down for continuous actions (movement). Use is_key_pressed /
is_key_released for one-shot events (jump, confirm, toggle).
Key enum
micro::key identifies physical key positions (scancodes), not characters.
The WASD cluster is always at the same physical position regardless of the
keyboard layout.
Letters
a 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
Digits
num0 num1 num2 num3 num4 num5 num6 num7 num8 num9
Function & control
f1 – f12, escape, enter, space, backspace, tab,
left_shift, right_shift, left_ctrl, right_ctrl,
left_alt, right_alt
Arrow and navigation
up, down, left, right, home, end, page_up, page_down,
insert, del
Example
if (kb.is_key_down(micro::key::w)) player.move_up(dt);
if (kb.is_key_down(micro::key::s)) player.move_down(dt);
if (kb.is_key_pressed(micro::key::f1)) toggle_hud();
if (kb.is_key_pressed(micro::key::escape)) win.close();