问题如题,时间最好精确些(ms)或者求得每两个数字输入的间隔时间,如何用C++实现,最好具体点,看有人说用键盘hook,但是没怎么看懂,求大神莅临指导。
2条回答 默认 最新
- Codec007 2015-04-23 09:58关注
#include
#include
#includeusing 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;
}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报