-2

As The Title Says I want to make a code or a app that runs in the background which clicks repeatedly so far I was only able to make a click code which is

 void Click() {
     INPUT iNPUTh = { 0 };
     iNPUTh.type = INPUT_MOUSE;
     iNPUTh.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
     SendInput(1, &iNPUTh, sizeof(iNPUTh));
     ZeroMemory(&iNPUTh, sizeof(iNPUTh));
     iNPUTh.type = INPUT_MOUSE;
     iNPUTh.mi.dwFlags = MOUSEEVENTF_LEFTUP;
     SendInput(1, &iNPUTh, sizeof(iNPUTh));
 }

int main() {
HWND hhProcess;
    hhProcess = FindWindow(NULL, L"ARK: Survival Evolved");
    if (hhProcess) {
        AllocConsole();
        cout << "Process Found!" << endl;
        
    }

    while (true) {
     if (GetAsyncKeyState(VK_Numpad0) {
    Click()
    }
    }

}

But my problem is that once I start to run it, it clicks on the surface what I want to happen is that it clicks on a background process

Yugii
  • 1
  • 2
  • Do you know or can you get the window handle to the background process? – Mark Ransom Jan 17 '21 at 17:48
  • yes HWND hhProcess; hhProcess = FindWindow(NULL, L"ARK: Survival Evolved"); if (hhProcess) { AllocConsole(); cout << "Process Found!" << endl; } while (true) { if (GetAsyncKeyState(VK_NUMPAD1)) { Click() } } – Yugii Jan 17 '21 at 23:00
  • Then you should be able to use [`PostMessageW`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-postmessagew). – Mark Ransom Jan 17 '21 at 23:05
  • Are you able to give a code example? I am a beginner on C++ I don't know how I am able to use this Thanks for the Info btw :) – Yugii Jan 17 '21 at 23:08
  • Does this answer your question? [How to simulate mouse click in a Directx game](https://stackoverflow.com/questions/14094278/how-to-simulate-mouse-click-in-a-directx-game) – Zeus Jan 18 '21 at 01:10
  • What i want to happen is that it clicks on a process that is running on a background such as clicking on the a background process while i am able to click on the active process – Yugii Jan 18 '21 at 05:08

1 Answers1

-1

I have found myself an answer :) I tried testing some codes myself and tried to use Post Message

PostMessage(hhProcess, WM_LBUTTONDOWN, 0, 0);
                Sleep(100);
                PostMessage(hhProcess, WM_LBUTTONUP, 0, 0);

everytime i press numpad 6 while the window is not active it punches i thank you guys for helping me find ways even tho sometimes i dont understand it :)

Now My Problem is How do i make it click on a certain coords x,y in the background

Yugii
  • 1
  • 2
  • "This works" and "This doesn't always fail" describe two very different scenarios. This proposed solution falls into the latter. [You can't simulate keyboard input with PostMessage](https://devblogs.microsoft.com/oldnewthing/20050530-11/?p=35513) explains just a few issues you haven't considered. There are lots more. – IInspectable Jan 18 '21 at 11:48