What I am trying to do is to create a program that will measure the time between each keystroke and then save it at the moment I have two programs one of them logs the keys in a text file and the other only counts the time between the time when enter is pressed and a. I am struggling with combining the two so that any key will start the stopwatch/timer and then the same key or a different key will stop the timer and then save that time to the text file. For example : If I wrote the word 'program' it would save the time it took for each keystroke. I hope you will offer your help :D
The stopwatch program:
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main() {
cout << "Hit enter to start timer" << endl;
cout << "Hit 'a' to stop timer" << endl;
cin.get();
unsigned short seconds = 0;
unsigned short minutes = 0;
while (!GetAsyncKeyState(0x41)) {
//while 'a' is not being pressed
seconds++;
if (seconds == 60) {
seconds = 0;
minutes++;
}
cout << std::setfill('0') << setw(2) << minutes << ":" << setfill('0') << setw(2) << seconds << endl;
Sleep(1000);
}
return 0;
}
The key logger
#include<iostream>
#include<windows.h>
#include<Winuser.h>
#include<string>
int Save(int key_stroke, char *file);
using namespace std;
int main()
{
char i;
int Save(int key_stroke, char *file);
while (1)
{
for (i = 8; i <= 190; i++)
{
if (GetAsyncKeyState(i) == -32767)
Save(i, "LOGER.TXT");
}
}
system ("PAUSE");
return 0;
}
int Save (int key_stroke, char *file)
{
cout<< key_stroke << endl;
return 0;
}