diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-02-01 23:32:55 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-02-01 23:32:55 +0100 |
| commit | 8062afc25e895cb49e76f6e26e51a7d4a1ad2df2 (patch) | |
| tree | f64e6522a84a8f58912b9e58a66c187fbcaadd78 /lib/nes/app/input/input-device-keyboard.hh | |
| parent | bf88e17d552d85cd18bc31757ef9d73049b327c4 (diff) | |
revamp input system
Diffstat (limited to 'lib/nes/app/input/input-device-keyboard.hh')
| -rw-r--r-- | lib/nes/app/input/input-device-keyboard.hh | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/nes/app/input/input-device-keyboard.hh b/lib/nes/app/input/input-device-keyboard.hh index dddcab6..23ee65c 100644 --- a/lib/nes/app/input/input-device-keyboard.hh +++ b/lib/nes/app/input/input-device-keyboard.hh @@ -1,6 +1,9 @@ #pragma once #include "nes/app/input/input-device.hh" +#include "nes/app/input/modifier-mask.hh" +#include "nes/app/input/input-event.hh" +#include "nes/app/input/key.hh" namespace nes::app { @@ -8,7 +11,37 @@ namespace nes::app class input_device_keyboard : public input_device { public: - virtual auto read_key_escape() -> bool = 0; + /// Read the current state of a key. + virtual auto read_key(key) -> bool = 0; + + /// Poll for events. + /// + /// As long as there are any buffered key-down or key-up events, they will be returned. After that, this + /// function will return input_event::type::none until there is another event. + virtual auto poll_event() -> input_event = 0; + + auto read_buttons() -> sys::button_mask final + { + auto res = sys::button_mask{}; + if (read_key(key::letter_w)) { res.add(sys::buttons::up); } + if (read_key(key::letter_a)) { res.add(sys::buttons::left); } + if (read_key(key::letter_s)) { res.add(sys::buttons::down); } + if (read_key(key::letter_d)) { res.add(sys::buttons::right); } + if (read_key(key::letter_k)) { res.add(sys::buttons::b); } + if (read_key(key::letter_l)) { res.add(sys::buttons::a); } + if (read_key(key::space)) { res.add(sys::buttons::select); } + if (read_key(key::enter)) { res.add(sys::buttons::start); } + return res; + } + + auto read_modifiers() -> modifier_mask + { + auto res = modifier_mask{}; + if (read_key(key::control_left) || read_key(key::control_right)) { res.add(modifiers::control); } + if (read_key(key::shift_left) || read_key(key::shift_right)) { res.add(modifiers::shift); } + if (read_key(key::alt_left) || read_key(key::alt_right)) { res.add(modifiers::alt); } + return res; + } protected: explicit input_device_keyboard() = default; |
