I am attempting to make a simple botting program for a game. I want this to be functional even when the game is out of focus or minimized. Because of this, I cannot use SendInput() as it simulates global events. I figured out that, to make this work, I must use the PostMessage() function. I made a test program that simulates input in Notepad:
#include <Windows.h>
HWND handle = FindWindow(NULL,CStringW("Untitled - Notepad"));
HWND edit = FindWindowEx(handle, NULL, CStringW("Edit"), NULL);
PostMessage(edit, WM_CHAR, 'a', 0 );
This example successfully simulates the clicking of "a" in notepad even if notepad is out of focus or minimized. I similarly got mouse events to work as well.
When I try this same thing for my game, however, I am unable to Post the click commands. After investigation, I found that the original handle is obtained but permission is denied when I call FindWindowEx(), and no handle is returned.
Is there a way to obtain 'edit' access to another process if it blocks this function?