Skip to content

Commit a1864d6

Browse files
committed
ignore dinput keypresses if window not in foreground
1 parent e3e7dc2 commit a1864d6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/directinput.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "dd.h"
77
#include "mouse.h"
88
#include "config.h"
9+
#include "utils.h"
910

1011
#ifdef _MSC_VER
1112
#include "detours.h"
@@ -86,13 +87,16 @@ static HRESULT WINAPI fake_did_GetDeviceData(
8687
pdwInOut,
8788
dwFlags,
8889
_ReturnAddress());
89-
*/
90+
*/
91+
92+
BOOL block_mouse = This == g_mouse_device && !g_mouse_locked && !g_config.devmode;
93+
BOOL in_background = FALSE;//g_ddraw.ref && g_ddraw.hwnd && !util_in_foreground(g_ddraw.hwnd);
9094

9195
HRESULT result = real_did_GetDeviceData(This, cbObjectData, rgdod, pdwInOut, dwFlags);
9296

93-
if (SUCCEEDED(result) && This == g_mouse_device && !g_mouse_locked && !g_config.devmode)
97+
if (SUCCEEDED(result))
9498
{
95-
if (pdwInOut)
99+
if ((block_mouse || in_background) && pdwInOut)
96100
{
97101
if (rgdod && *pdwInOut > 0 && cbObjectData > 0)
98102
{
@@ -110,11 +114,14 @@ static HRESULT WINAPI fake_did_GetDeviceState(IDirectInputDeviceA* This, DWORD c
110114
{
111115
//TRACE("DirectInput GetDeviceState(This=%p, cbData=%lu, lpvData=%p) [%p]\n", This, cbData, lpvData, _ReturnAddress());
112116

117+
BOOL block_mouse = This == g_mouse_device && !g_mouse_locked && !g_config.devmode;
118+
BOOL in_background = g_ddraw.ref && g_ddraw.hwnd && !util_in_foreground(g_ddraw.hwnd);
119+
113120
HRESULT result = real_did_GetDeviceState(This, cbData, lpvData);
114121

115-
if (SUCCEEDED(result) && This == g_mouse_device && !g_mouse_locked && !g_config.devmode)
122+
if (SUCCEEDED(result))
116123
{
117-
if (cbData > 0 && lpvData)
124+
if ((block_mouse || in_background) && cbData > 0 && lpvData)
118125
{
119126
memset(lpvData, 0, cbData);
120127
}

0 commit comments

Comments
 (0)