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!
#include <iostream>
#include <conio.h>
usingnamespace 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
{}
}
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.