diff --git a/rpcs3/Input/raw_mouse_handler.cpp b/rpcs3/Input/raw_mouse_handler.cpp index f271470c46..b7e568a9e7 100644 --- a/rpcs3/Input/raw_mouse_handler.cpp +++ b/rpcs3/Input/raw_mouse_handler.cpp @@ -284,35 +284,48 @@ void raw_mouse_handler::Init(const u32 max_connect) } #ifdef _WIN32 - if (max_connect && !m_raw_mice.empty()) - { - // Initialize and center all mice - for (auto& [handle, mouse] : m_raw_mice) - { - mouse.update_window_handle(); - mouse.center_cursor(); - } - - // Get the window handle of the first mouse - raw_mouse& mouse = m_raw_mice.begin()->second; - - std::vector raw_input_devices; - raw_input_devices.push_back(RAWINPUTDEVICE { - .usUsagePage = HID_USAGE_PAGE_GENERIC, - .usUsage = HID_USAGE_GENERIC_MOUSE, - .dwFlags = 0, - .hwndTarget = mouse.window_handle() - }); - if (!RegisterRawInputDevices(raw_input_devices.data(), ::size32(raw_input_devices), sizeof(RAWINPUTDEVICE))) - { - input_log.error("raw_mouse_handler: RegisterRawInputDevices failed: %s", fmt::win_error{GetLastError(), nullptr}); - } - } + register_raw_input_devices(); #endif type = mouse_handler::raw; } +#ifdef _WIN32 +void raw_mouse_handler::register_raw_input_devices() +{ + if (m_registered_raw_input_devices || !m_info.max_connect || m_raw_mice.empty()) + { + return; + } + + // Initialize and center all mice + for (auto& [handle, mouse] : m_raw_mice) + { + mouse.update_window_handle(); + mouse.center_cursor(); + } + + // Get the window handle of the first mouse + raw_mouse& mouse = m_raw_mice.begin()->second; + + std::vector raw_input_devices; + raw_input_devices.push_back(RAWINPUTDEVICE { + .usUsagePage = HID_USAGE_PAGE_GENERIC, + .usUsage = HID_USAGE_GENERIC_MOUSE, + .dwFlags = 0, + .hwndTarget = mouse.window_handle() + }); + + if (!RegisterRawInputDevices(raw_input_devices.data(), ::size32(raw_input_devices), sizeof(RAWINPUTDEVICE))) + { + input_log.error("raw_mouse_handler: RegisterRawInputDevices failed: %s", fmt::win_error{GetLastError(), nullptr}); + return; + } + + m_registered_raw_input_devices = true; +} +#endif + void raw_mouse_handler::enumerate_devices(u32 max_connect) { input_log.notice("raw_mouse_handler: enumerating devices (max_connect=%d)", max_connect); diff --git a/rpcs3/Input/raw_mouse_handler.h b/rpcs3/Input/raw_mouse_handler.h index b1f693d358..4a20e4bd27 100644 --- a/rpcs3/Input/raw_mouse_handler.h +++ b/rpcs3/Input/raw_mouse_handler.h @@ -89,6 +89,11 @@ public: private: void enumerate_devices(u32 max_connect); +#ifdef _WIN32 + void register_raw_input_devices(); + bool m_registered_raw_input_devices = false; +#endif + bool m_ignore_config = false; std::map m_raw_mice; std::function m_mouse_press_callback;