MouseEvents (and template matching)

First of all hello, and thank you for taking a look at my problem.
Let me just give you a little frame on what I was requested to do.
Someone asked me if I could write him a little program for the game "SCUM"
that automatically reloggs him into *his* server after a restart.
For that I have to do three things:
1. Click the OK-Button from the "lost connection to server" prompt
2. Click the "Multiplayer" button
3. Enter the server ip in the "IP-Edit-field" and hit enter

My thought was to make a screenshot from the game window (which I already have)
and then search for the buttons using images.
For the template matching I use opencv.

I have several issues with that:
1. The template matching instantly looses accuracy when the window has different resolutions.
2. The template matching in general does not really work
3. I want to send "mouse events" to the game window, but it shouldn't matter if the window is minimized or not, and I found a function called "SendMessage", but it's not really working:

1
2
3
4
5
6
7
8
9
bool mouseClick(HWND hwnd, int x, int y)
{
   // some sources said this to be required, but had no explaination why
   if (!SetForegroundWindow(hwnd)) return false;

   return
      SendMessageA(hwnd, WM_LBUTTONDOWN, NULL, MAKELPARAM(x, y)) &&
      SendMessageA(hwnd, WM_LBUTTONUP, NULL, MAKELPARAM(x, y))
}


Oher ideas I had:
1. Call game functions like in game hacking, but it's risky (Easy Anti Cheat)
2. Just use python which solves the problems I have right now, but other will come up (and I'm better at C++)

Any ideas how to solve at least the SendMessage problem?
I know the other things don't belong to windows, but maybe someone has another idea I could try

thanks in advance ;)
Last edited on
Just use python which solves the problems
If it can be solved in python it should be doable in c++ as well. So how it is done there?

In order to send a message to a window you need the HWND of that particular window. You can use several function like FindWindow.(...) for this. Take a look here:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindowa
I didn't attempt the code, but note that you probably need to run your program as an admin to properly send messages to other processes.
Registered users can post here. Sign in or register to post.