My mouse movements are making the SendMessage autopot/autoheal to fail

59 Views Asked by At

I'm trying to make a game autopot/autoheal with SendMessage:

using_arrowslot = true;

// click potion
SendMessage(Window, WM_MOUSEMOVE, 0, MAKELPARAM(potx, poty));
SendMessage(Window, WM_RBUTTONDOWN, 0, MAKELPARAM(potx, poty));
SendMessage(Window, WM_RBUTTONUP, 0, MAKELPARAM(potx, poty));

// click player
SendMessage(Window, WM_MOUSEMOVE, 0, MAKELPARAM(playerx, playery));
SendMessage(Window, WM_LBUTTONDOWN, 0, MAKELPARAM(playerx, playery));
SendMessage(Window, WM_LBUTTONUP, 0, MAKELPARAM(playerx, playery));
start_manapot += std::chrono::seconds(seconds_to_cast);
using_arrowslot = false;

The problem is that those SendMessages will send clicks to wrong positions sometimes as I'm moving the mouse while playing.

So, what I've tested to make it accurate, is to take control of the mouse while the SendMessage is being processed.

The way I'm trying is hooking WndProc and try to "filter" by my params:

LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    if (ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
        return true; 

    if (menuShow || (using_arrowslot && lParam != 29426537 && lParam != 18024234))
        return 1;

    return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
}

I don't find any difference in results of running with the WndProc hook or without it. It's not accurate while using mouse ingame.

I'm not sure... what you guys do in this situations...

How can I make the SendMessage to work without being affected by my mouse or keyboard?

0

There are 0 best solutions below