Please help me with a program

Hi can anyone tell me how to do a program that whenever i press '2' then immidietly starts and press 2 unlimited times after x miliseconds each time, and when i press again '2' then it stops.Can someone help me with this?
(sorry for my bad english :/)
Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <conio.h>

using namespace std;
void delay();

int main()
{
while (_getch() != '2')
		cout << "Press 2 to start \n";

	do
	{
		cout << "2";
		delay();
		if (_kbhit() && _getch() == '2') // Break if 2 is hit
			break;
	} while (true);

return(0);
}

void delay()
{
for(long i = 0; i < 10000000; ++i) // Tinker with this number till you get the reqd speed
{}
}
Last edited on
thanks very very much
Last edited on
well, if its not a big trouble for you can you make it to works on other windows too?(or someone else)
Last edited on
This is not a forum for such requests. You should put some effort and write some code then ask for help if you're stuck somewhere.

If you're on Windows you can check out SetWindowsHookEx to setup a global keyboard hook. Then you can use respective windows functions to send key presses.

Or you could use external low-level interception libraries which are less likely to be detected if that's a concern.
ok thanks and sorry :/
Topic archived. No new replies allowed.