問題如題,時間最好精確些(ms)或者求得每兩個數字輸入的間隔時間,如何用C++實現,最好具體點,看有人說用鍵盤hook,但是沒怎麼看懂,求大神莅臨指導。
#include
#include
#include
using namespace std;
class KeyTime{
public:
int KeyCode;//按下的鍵值
time_t* Time = new time_t();//按下鍵的時間
};
int main(int argc, char *argv[], char *envp[]){
KeyTime* c[6];//輸入次數
//輸入數字
cout << "請按鍵:";
for (int i = 0; i < 6; i++)
{
KeyTime* Item = new KeyTime();
Item->KeyCode = _getch();
time(Item->Time);
c[i] = Item;
cout << Item->KeyCode;
}
cout << endl;
//展示結果
for (int j = 0; j < 6; j++){
char buffer[32];
struct tm newtime;
localtime_s(&newtime, c[j]->Time);
strftime(buffer, 32, "%Y-%m-%d %H:%M:%S", &newtime);
cout << "按下鍵" << c[j]->KeyCode << "於" << buffer;
if (j > 0)
{
cout << "相差秒數" << difftime(*(c[j]->Time), *(c[j - 1]->Time));
}
cout << endl;
}
getchar();
return 0;
}