#include "input.hpp" #include #include #include void UserInputObserver::listen() noexcept { while (true) { char character = 0; if (std::cin.read(&character, 1).fail()) { continue; } _currently_pressed_mutex.lock(); if (character != _currently_pressed) { _currently_pressed = character; } _currently_pressed_mutex.unlock(); } } bool UserInputObserver::is_key_pressed(Key key) noexcept { _currently_pressed_mutex.lock(); const auto is_key_pressed = key == _currently_pressed; _currently_pressed_mutex.unlock(); return is_key_pressed; } void UserInputObserver::clear_currently_pressed() noexcept { _currently_pressed_mutex.lock(); _currently_pressed = 0; _currently_pressed_mutex.unlock(); }