C++ Finding Window and executing a Keyboard event
So today I was bored and decided to make a Program which executes a Keyboard action, since I thought it might not be that hard...
And I've came across some problems..
1.It's not able to find the xyz.exe example, how could I do it via the pID?
2.Even without the FindWindow check I'm not able to jump with the "VK_SPACE;"was pretty obvious tho... so I searched a bit and found something that's called
Key Events and I should use that but I'm not able to find something usefull...
3. Please don't just send a code that's done and works, I wanna do it myself...
Would this code be overall alright?
Sleep is on x because I still have to check when it's the perfect time to execute that...
Thanks for help in advance!
And sorry for asking such a noobish question.
//EDIT
Change overall program + topic @Hugo Boss could you please change the titel to "C++ Finding Window and executing a Keyboard event"
thanks Hugo Boss for changing the titel!
And I've came across some problems..
1.It's not able to find the xyz.exe example, how could I do it via the pID?
2.Even without the FindWindow check I'm not able to jump with the "VK_SPACE;"was pretty obvious tho... so I searched a bit and found something that's called
Key Events and I should use that but I'm not able to find something usefull...
3. Please don't just send a code that's done and works, I wanna do it myself...
Would this code be overall alright?
Sleep is on x because I still have to check when it's the perfect time to execute that...
Code:
#include <Windows.h>
#include <iostream>
int main(){
boolean isKeyNOTActivated = TRUE;
boolean action = TRUE;
std::cout << "\t\tProgramXYZ" << std::endl;
retry:
HWND hWnd = FindWindowW(0, L"xyz.exe");
if (hWnd == 0)
{
std::cerr << "Can't find xyz." << std::endl;
goto retry;
}
else
{
stop:
std::cout << "Press F9 to activate!" << std::endl;
while (isKeyNOTActivated == TRUE){
if (GetAsyncKeyState(VK_F9))
{
isKeyNOTActivated = FALSE;
do{
VK_SPACE;
Sleep(x); //will do that later...
if (GetAsyncKeyState(VK_F10)){
action = FALSE;
goto retry;
}
} while (action == TRUE);
}
}
}
}
And sorry for asking such a noobish question.
//EDIT
Change overall program + topic @Hugo Boss could you please change the titel to "C++ Finding Window and executing a Keyboard event"
thanks Hugo Boss for changing the titel!
