Refactor input handler (#15933)

This commit is contained in:
y5nw
2025-03-30 18:16:20 +02:00
committed by GitHub
parent 309c0a0cb6
commit 4cd2273349
5 changed files with 168 additions and 254 deletions

View File

@@ -49,6 +49,11 @@ class KeyPress
return !(*this == o);
}
// Used for e.g. std::set
bool operator<(KeyPress o) const {
return scancode < o.scancode;
}
// Check whether the keypress is valid
operator bool() const
{
@@ -60,11 +65,22 @@ class KeyPress
static KeyPress getSpecialKey(const std::string &name);
private:
using value_type = std::variant<u32, irr::EKEY_CODE>;
bool loadFromScancode(const std::string &name);
void loadFromKey(irr::EKEY_CODE keycode, wchar_t keychar);
std::string formatScancode() const;
std::variant<u32, irr::EKEY_CODE> scancode = irr::KEY_UNKNOWN;
value_type scancode = irr::KEY_UNKNOWN;
friend std::hash<KeyPress>;
};
template <>
struct std::hash<KeyPress>
{
size_t operator()(KeyPress kp) const noexcept {
return std::hash<KeyPress::value_type>{}(kp.scancode);
}
};
// Global defines for convenience