10 #include <sys/select.h>
20 using std::chrono::duration_cast;
21 using std::chrono::milliseconds;
22 using std::chrono::system_clock;
31 constexpr
unsigned char UP_BYTES[] = {0x1B, 0x5B, 0x41};
32 constexpr
unsigned char DOWN_BYTES[] = {0x1B, 0x5B, 0x42};
34 constexpr
unsigned char LEFT_BYTES[] = {0x1B, 0x5B, 0x44};
37 return 0x61 <= c && c <= 0x7A;
40 return 0x41 <= c && c <= 0x5A;
43 return 0x20 <= c && c <= 0x7F;
82 inline std::string
prefix() const noexcept final {
return "keyboard"; }
88 void write(Dictionary& output)
final;
99 Key map_char_to_key(
unsigned char* buf);
111 system_clock::time_point last_key_poll_time_;
bool is_printable_ascii(unsigned char c)
constexpr unsigned char LEFT_BYTES[]
constexpr unsigned char UP_BYTES[]
constexpr unsigned char DOWN_BYTES[]
bool is_lowercase_alpha(unsigned char c)
bool is_uppercase_alpha(unsigned char c)
constexpr ssize_t kMaxKeyBytes
Maximum number of bytes to encode a key.
constexpr int64_t kPollingIntervalMS
Polling interval in milliseconds.
constexpr unsigned char RIGHT_BYTES[]
Source for reading Keyboard inputs.
Keyboard()
Constructor sets up the terminal in non-canonical mode where input is available immediately without w...
~Keyboard() override
Destructor.
std::string prefix() const noexcept final
Prefix of output in the observation dictionary.
void write(Dictionary &output) final
Write output to a dictionary.