How do I do a key press function?

I just started learning c++ a couple of days ago, and I have been searching the internet all day today but I cannot find anything about this.

#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
for( ; ; ){
SetCursorPos(956,485);
Sleep(10);
SetCursorPos(1015,567);
Sleep(10);
SetCursorPos(915,567);
Sleep(10);
}

cin.ignore();

return 0;
}

The thing I want to do is activate the loop when I press a specified key on the keyboard. With other coding languages it is if(keyPressed("") ) { } if that helps to figure out what i'm trying to do. It would be great if you could help me :D

Sorry for being a complete scrub :(
Last edited on
Thanks, I'll look into it :D
It could look something like this:


#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{
while(true)
{
if(GetAsyncKeyState(/*only as an example*/VK_SPACE))// More virtual key codes at: https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
{
while(true)//or for(;;)
{
SetCursorPos(956,485);
Sleep(10);
SetCursorPos(1015,567);
Sleep(10);
SetCursorPos(915,567);
Sleep(10);

/*if(GetAsyncKeyState(VK_ESCAPE))
exit;*/
}
cin.ignore();
}
}
return 0;
}
Last edited on
Topic archived. No new replies allowed.