summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2019-03-09 09:57:37 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2019-03-29 09:04:16 -0500
commiteadbdd6bc389cd89c3e3e57a31dabaeadf161865 (patch)
treee64941bcb188067cf5355a9cee1a74b42a5ae6ab /Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp
parentd26c1ce24d9108114d7eab97cfc2ab4f3eea28ee (diff)
ControllerInterface/Win32: Prevent devcies from losing their "id" on a hotplug event.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp
index 384174a3f1..23746e61db 100644
--- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp
@@ -29,12 +29,13 @@ static const struct
#include "InputCommon/ControllerInterface/DInput/NamedKeys.h" // NOLINT
};
-// lil silly
-static HWND m_hwnd;
+// Prevent duplicate keyboard/mouse devices.
+static bool s_keyboard_mouse_exists = false;
-void InitKeyboardMouse(IDirectInput8* const idi8, HWND _hwnd)
+void InitKeyboardMouse(IDirectInput8* const idi8)
{
- m_hwnd = _hwnd;
+ if (s_keyboard_mouse_exists)
+ return;
// mouse and keyboard are a combined device, to allow shift+click and stuff
// if that's dumb, I will make a VirtualDevice class that just uses ranges of inputs/outputs from
@@ -63,6 +64,8 @@ void InitKeyboardMouse(IDirectInput8* const idi8, HWND _hwnd)
KeyboardMouse::~KeyboardMouse()
{
+ s_keyboard_mouse_exists = false;
+
// kb
m_kb_device->Unacquire();
m_kb_device->Release();
@@ -75,6 +78,8 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device,
const LPDIRECTINPUTDEVICE8 mo_device)
: m_kb_device(kb_device), m_mo_device(mo_device)
{
+ s_keyboard_mouse_exists = true;
+
m_kb_device->Acquire();
m_mo_device->Acquire();
@@ -237,5 +242,5 @@ ControlState KeyboardMouse::Cursor::GetState() const
{
return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0));
}
-}
-}
+} // namespace DInput
+} // namespace ciface