Skip to content

Commit

Permalink
ignore dinput keypresses if window not in foreground
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Oct 27, 2024
1 parent e3e7dc2 commit a1864d6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/directinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "dd.h"
#include "mouse.h"
#include "config.h"
#include "utils.h"

#ifdef _MSC_VER
#include "detours.h"
Expand Down Expand Up @@ -86,13 +87,16 @@ static HRESULT WINAPI fake_did_GetDeviceData(
pdwInOut,
dwFlags,
_ReturnAddress());
*/
*/

BOOL block_mouse = This == g_mouse_device && !g_mouse_locked && !g_config.devmode;
BOOL in_background = FALSE;//g_ddraw.ref && g_ddraw.hwnd && !util_in_foreground(g_ddraw.hwnd);

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

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

BOOL block_mouse = This == g_mouse_device && !g_mouse_locked && !g_config.devmode;
BOOL in_background = g_ddraw.ref && g_ddraw.hwnd && !util_in_foreground(g_ddraw.hwnd);

HRESULT result = real_did_GetDeviceState(This, cbData, lpvData);

if (SUCCEEDED(result) && This == g_mouse_device && !g_mouse_locked && !g_config.devmode)
if (SUCCEEDED(result))
{
if (cbData > 0 && lpvData)
if ((block_mouse || in_background) && cbData > 0 && lpvData)
{
memset(lpvData, 0, cbData);
}
Expand Down

0 comments on commit a1864d6

Please sign in to comment.