Qt: Allow rebinding keyboard controls (#779)
* Initial input UI draft Co-Authored-By: Paris Oplopoios <parisoplop@gmail.com> * More keybinding work Co-Authored-By: Paris Oplopoios <parisoplop@gmail.com> * Nit Co-Authored-By: Paris Oplopoios <parisoplop@gmail.com> * More nits Co-Authored-By: Paris Oplopoios <parisoplop@gmail.com> --------- Co-authored-by: Paris Oplopoios <parisoplop@gmail.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "services/hid.hpp"
|
||||
|
||||
#include <bit>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ipc.hpp"
|
||||
#include "kernel.hpp"
|
||||
@@ -242,4 +244,61 @@ void HIDService::updateInputs(u64 currentTick) {
|
||||
kernel.signalEvent(e.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Key serialization helpers
|
||||
namespace HID::Keys {
|
||||
const char* keyToName(u32 key) {
|
||||
static std::unordered_map<u32, const char*> keyMap = {
|
||||
{A, "A"},
|
||||
{B, "B"},
|
||||
{Select, "Select"},
|
||||
{Start, "Start"},
|
||||
{Right, "D-Pad Right"},
|
||||
{Left, "D-Pad Left"},
|
||||
{Up, "D-Pad Up"},
|
||||
{Down, "D-Pad Down"},
|
||||
{R, "R"},
|
||||
{L, "L"},
|
||||
{X, "X"},
|
||||
{Y, "Y"},
|
||||
{ZL, "ZL"},
|
||||
{ZR, "ZR"},
|
||||
{CirclePadRight, "CirclePad Right"},
|
||||
{CirclePadLeft, "CirclePad Left"},
|
||||
{CirclePadUp, "CirclePad Up"},
|
||||
{CirclePadDown, "CirclePad Down"},
|
||||
};
|
||||
|
||||
auto it = keyMap.find(key);
|
||||
return it != keyMap.end() ? it->second : "Unknown key";
|
||||
}
|
||||
|
||||
u32 nameToKey(std::string name) {
|
||||
static std::unordered_map<std::string, u32> keyMap = {
|
||||
{"a", A},
|
||||
{"b", B},
|
||||
{"select", Select},
|
||||
{"start", Start},
|
||||
{"d-pad right", Right},
|
||||
{"d-pad left", Left},
|
||||
{"d-pad up", Up},
|
||||
{"d-pad down", Down},
|
||||
{"r", R},
|
||||
{"l", L},
|
||||
{"x", X},
|
||||
{"y", Y},
|
||||
{"zl", ZL},
|
||||
{"zr", ZR},
|
||||
{"circlepad right", CirclePadRight},
|
||||
{"circlepad left", CirclePadLeft},
|
||||
{"circlepad up", CirclePadUp},
|
||||
{"circlepad down", CirclePadDown},
|
||||
};
|
||||
|
||||
std::transform(name.begin(), name.end(), name.begin(), [](char c) { return std::tolower(c); });
|
||||
auto it = keyMap.find(name);
|
||||
|
||||
return it != keyMap.end() ? it->second : HID::Keys::Null;
|
||||
}
|
||||
} // namespace HID::Keys
|
||||
|
||||
Reference in New Issue
Block a user