how can i make my program reset without spamming?

closed account (9i3hURfi)
what the title says, when i use while(true) i press my hotkey to add a certain amount of points, it spams it really fast and adds a ton more than i want

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cout << "press F3 to add 750 points\n";
	system("pause");

	// I want it to reset back to here
	while (true)
	{
		if (GetAsyncKeyState(VK_F3))
		{
			DWORD oldProtect;
			DWORD value = 0;
			VirtualProtect((LPVOID)0x018EF124, 4, PAGE_READWRITE, &oldProtect);
			ReadProcessMemory(hProcess, (LPVOID)0x018EF124, &value, sizeof(value), 0);
			value += 750;
			WriteProcessMemory(hProcess, (LPVOID)0x018EF124, &value, sizeof(value), NULL);
			VirtualProtect((LPVOID)0x018EF124, 4, oldProtect, &oldProtect);
			cout << "Points have been added \n";
		}
		}
GetAsyncKeyState will return the real-time state of the key in the high bit.

So unless you can press and release the key really really fast (ie, faster than it takes your program to run the loop one time ... note that this is not humanly possibly) -- your program is going to think you held the button down and will keep doing that stuff until the key is released.


Some implementations of GetAsyncKeyState I believe have the pressed/released state in the low bit. So you might be able to accomplish what you want by just looking at the low bit:

 
if (GetAsyncKeyState(VK_F3) & 0x0001)  //<- look at low bit only 


If that doesn't work, the next thing I'd try is keeping a boolean value to mark the previous state of the key... and only do that job when the state transitions from released->pressed.
closed account (9i3hURfi)
it worked thank you so much :)
Topic archived. No new replies allowed.