Skip to content

Commit

Permalink
Use low-level mouse/keyboard hook to avoid calling various functions …
Browse files Browse the repository at this point in the history
…in ImGui's end-of-frame handler
  • Loading branch information
Kaldaien committed Dec 27, 2024
1 parent bb6a1f3 commit 8e74dd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/imgui/imgui_user.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3196,16 +3196,16 @@ SK_ImGui_UpdateMouseButtons (bool bActive, ImGuiIO& io)
return false;
}

POINT SK_ImGui_LastKnownCursorPos;

void
SK_ImGui_User_NewFrame (void)
{
SK_Window_HandleOutOfBandMovement ();

SK_HID_ProcessGamepadButtonBindings ();

// Hacky solution for missed messages causing no change in cursor pos
//
POINT cursor_pos = { };
POINT cursor_pos = {};
SK_GetCursorPos (&cursor_pos);

bool capture_mouse = SK_ImGui_WantMouseCapture (false, &cursor_pos);
Expand Down Expand Up @@ -3493,6 +3493,9 @@ SK_ImGui_User_NewFrame (void)
const bool bActive =
SK_IsGameWindowActive ();

// Avoid overhead from calling SK_GetAsyncKeyState (...)
// repeatedly; we already have a low-level keyboard hook!
#ifdef SK_DOES_NOT_TRUST_LOW_LEVEL_KEYBOARD_HOOK
if (bActive && new_input)
{
for (UINT i = 7 ; i < 255 ; ++i)
Expand All @@ -3501,6 +3504,7 @@ SK_ImGui_User_NewFrame (void)
((SK_GetAsyncKeyState (i) & 0x8000) != 0x0);
}
}
#endif

if (! bActive)
RtlZeroMemory (&io.KeysDown [7], sizeof (bool) * 248);
Expand Down
6 changes: 6 additions & 0 deletions src/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7172,6 +7172,8 @@ SK_Platform_GetUserName (char* pszName, int max_len = 512)
}


extern POINT SK_ImGui_LastKnownCursorPos;

LRESULT
CALLBACK
SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)
Expand All @@ -7187,6 +7189,8 @@ SK_ImGui_MouseProc (int code, WPARAM wParam, LPARAM lParam)

bool bPassthrough = true;

SK_ImGui_LastKnownCursorPos = mhs->pt;

if (mhs->hwnd != 0)
if ( mhs->wHitTestCode == HTCLIENT ||
mhs->wHitTestCode == HTTRANSPARENT )
Expand Down Expand Up @@ -7385,6 +7389,8 @@ SK_ImGui_KeyboardProc (int code, WPARAM wParam, LPARAM lParam)
auto& io =
ImGui::GetIO ();

io.KeysDown [vKey] = isPressed;

if (io.KeyAlt && vKey == VK_F4 && isPressed)
{
if (SK_ImGui_Active () || config.input.keyboard.catch_alt_f4 || config.input.keyboard.override_alt_f4 || keyboard_capture)
Expand Down

0 comments on commit 8e74dd6

Please sign in to comment.