diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 1e617d6c24..5aca9f5280 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -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); diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index cd056af0d8..e57e1c7682 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -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& inputs) +{ + AddInput(new CombinedInput(std::move(name), {FindInput(inputs.first), FindInput(inputs.second)})); +} + // // DeviceQualifier :: ToString // diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index 43e61e53fd..495c64cbde 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -147,6 +147,23 @@ protected: AddInput(new FullAnalogSurface(high, low)); } + class CombinedInput final : public Input + { + public: + using Inputs = std::pair; + + 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 m_inputs; + }; + + void AddCombinedInput(std::string name, const std::pair& inputs); + private: int m_id; std::vector m_inputs; diff --git a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm index 7c4673acd7..d594ac9e5f 100644 --- a/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm +++ b/Source/Core/InputCommon/ControllerInterface/Quartz/QuartzKeyboardAndMouse.mm @@ -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(window) window] windowNumber]; // cursor, with a hax for-loop diff --git a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp index d049f22c8c..9ec1c2be35 100644 --- a/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Xlib/XInput2.cpp @@ -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));