C++ Finding Window and executing a Keyboard event

Posts 1–5 of 5 · Page 1 of 1
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...

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);

			}
		}

	} 
}
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!
1. in your find window you have to use window's name instead of process' name.
2. "VK_SPACE"? where is the function?
3. ok np
You have luck man, here a little snippet in c++ by me
github.com/iurimattos/ReadMemoryValue/blob/master/main.cpp
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us