我要做的是创建一个程序来测量每次击键之间的时间,然后在我有两个程序的时刻保存它,其中一个程序将密钥记录在文本文件中,另一个只计算时间在按下输入和a之间的时间。我正在努力将两者结合起来,这样任何键都会启动秒表/计时器,然后相同的键或不同的键将停止计时器,然后将该时间保存到文本文件中。 例如:如果我写了“程序”这个词,它将节省每次击键所花费的时间。我希望你能提供帮助:D
秒表计划:
#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;
}
键记录器
#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;
}
答案 0 :(得分:-1)
#include<iostream>
#include<windows.h>
#include<Winuser.h>
#include<string>
#include <iomanip>
#include<ctime>
#include<cstdio>
int Save(int key_stroke, char *file);
char i;
clock_t corrected = 0;
using namespace std;
int main()
{
int Save(int key_stroke, char *file);
while (1)
{
for (i = 8; i <= 190; i++)
{
if
(GetAsyncKeyState(i) == -32767 )
{
clock_t start = clock();
cout<<"clock: " << start-corrected <<endl;
Save(i, "LOGER.TXT");
clock_t end= clock();
corrected=clock();
}
}
}
system ("PAUSE");
return 0;
}
int Save (int key_stroke, char *file)
{
cout<< key_stroke << endl;
return 0;
}