ControllerInterface: Add platform consistent names for modifier keys.

This commit is contained in:
Jordan Woyak 2019-10-25 19:33:59 -05:00
parent d2729df281
commit f015c99a51
5 changed files with 65 additions and 0 deletions

View File

@ -87,6 +87,11 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device,
for (u8 i = 0; i < sizeof(named_keys) / sizeof(*named_keys); ++i)
AddInput(new Key(i, m_state_in.keyboard[named_keys[i].code]));
// Add combined left/right modifiers with consistent naming across platforms.
AddCombinedInput("Alt", {"LMENU", "RMENU"});
AddCombinedInput("Shift", {"LSHIFT", "RSHIFT"});
AddCombinedInput("Ctrl", {"LCONTROL", "RCONTROL"});
// MOUSE
DIDEVCAPS mouse_caps = {};
mouse_caps.dwSize = sizeof(mouse_caps);

View File

@ -103,6 +103,39 @@ bool Device::FullAnalogSurface::IsMatchingName(std::string_view name) const
return old_name == name;
}
Device::CombinedInput::CombinedInput(std::string name, const Inputs& inputs)
: m_name(std::move(name)), m_inputs(inputs)
{
}
ControlState Device::CombinedInput::GetState() const
{
ControlState result = 0;
if (m_inputs.first)
result = m_inputs.first->GetState();
if (m_inputs.second)
result = std::max(result, m_inputs.second->GetState());
return result;
}
std::string Device::CombinedInput::GetName() const
{
return m_name;
}
bool Device::CombinedInput::IsDetectable()
{
return false;
}
void Device::AddCombinedInput(std::string name, const std::pair<std::string, std::string>& inputs)
{
AddInput(new CombinedInput(std::move(name), {FindInput(inputs.first), FindInput(inputs.second)}));
}
//
// DeviceQualifier :: ToString
//

View File

@ -147,6 +147,23 @@ protected:
AddInput(new FullAnalogSurface(high, low));
}
class CombinedInput final : public Input
{
public:
using Inputs = std::pair<Input*, Input*>;
CombinedInput(std::string name, const Inputs& inputs);
ControlState GetState() const override;
std::string GetName() const override;
bool IsDetectable() override;
private:
const std::string m_name;
const std::pair<Input*, Input*> m_inputs;
};
void AddCombinedInput(std::string name, const std::pair<std::string, std::string>& inputs);
private:
int m_id;
std::vector<Input*> m_inputs;

View File

@ -143,6 +143,11 @@ KeyboardAndMouse::KeyboardAndMouse(void* window)
for (int keycode = 0; keycode < 0x80; ++keycode)
AddInput(new Key(keycode));
// Add combined left/right modifiers with consistent naming across platforms.
AddCombinedInput("Alt", {"Left Alt", "Right Alt"});
AddCombinedInput("Shift", {"Left Shift", "Right Shift"});
AddCombinedInput("Ctrl", {"Left Control", "Right Control"});
m_windowid = [[reinterpret_cast<NSView*>(window) window] windowNumber];
// cursor, with a hax for-loop

View File

@ -172,6 +172,11 @@ KeyboardMouse::KeyboardMouse(Window window, int opcode, int pointer, int keyboar
delete temp_key;
}
// Add combined left/right modifiers with consistent naming across platforms.
AddCombinedInput("Alt", {"Alt_L", "Alt_R"});
AddCombinedInput("Shift", {"Shift_L", "Shift_R"});
AddCombinedInput("Ctrl", {"Control_L", "Control_R"});
// Mouse Buttons
for (int i = 0; i < 32; i++)
AddInput(new Button(i, &m_state.buttons));