QuestionC++ check if button pressed

Posts 1–4 of 4 · Page 1 of 1
C++ check if button pressed
In c++ how do i check if a key is pressed ( not GetAsyncKeyState/GetKeyState because when I hold it down it spams the command)

Code:
int main()
{
	while (1)
	{
		if (GetAsyncKeyState(VK_INSERT)) {
			//Command
		}
	}
}
Quote Originally Posted by lolman40 View Post
In c++ how do i check if a key is pressed ( not GetAsyncKeyState/GetKeyState because when I hold it down it spams the command)

Code:
int main()
{
	while (1)
	{
		if (GetAsyncKeyState(VK_INSERT)) {
			//Command
		}
	}
}
Code:
GetAsyncKeyState(button) & 1;

So, your code would look like:
Code:
int main()
{
	while (1)
	{
		if (GetAsyncKeyState(VK_INSERT) & 1) {
			//Command
		}
	}
}
Quote Originally Posted by affe2626 View Post
Code:
GetAsyncKeyState(button) & 1;

So, your code would look like:
Code:
int main()
{
	while (1)
	{
		if (GetAsyncKeyState(VK_INSERT) & 1) {
			//Command
		}
	}
}
It is still spamming tough.
code tag
dude that is simple code


Code:
int main()
{
	bool pressed = false;

	while (1)
	{
		
		if (GetAsyncKeyState(VK_INSERT) && !pressed) {
			pressed = true;
			//Command
		} else {
			pressed = false;
		}		
	}
}
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?