高级计时器

来源:互联网 发布:叮叮监控软件介绍 编辑:程序博客网 时间:2024/05/18 16:37

渐渐地,博主发现了一个巨大的BUG:计时器用起来不灵敏,不好用。。。等博主有空再来改吧。

这就是一个计时器的变种,加入了键钮操作。没什么难的,几十行代码而已、

// making by zhouzhuan#include <bits/stdc++.h>#include <Windows.h>using namespace std;#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000)? 1 : 0)     int l, r;int hour, minute, second;void get_timer(){system("cls");printf("------------------计时器------------------\n");printf("                      making by  zhouzhuan\n");//      begin   segmentation time                 endprintf("开始(b) 分割(s) Time : %.2d : %.2d : %.2d 清除(e)\n", hour, minute, second);return ;} int main(){while (true){// initializationint a[10005], len = 0;hour = 0, minute = 0, second = 0;get_timer();// start timerwhile (!KEY_DOWN('B')) ;// get left timel = clock();//printf("%d\n", l);//Sleep(5000);while (true){// end timerif (KEY_DOWN('E'))break;else if (KEY_DOWN('S')){//get right timer = clock();a[++len] = r - l;}//else//{get_timer();// next timesecond++;if (second >= 60){minute++;second = 0;} if (minute >= 60){hour++;minute = 0;}if (hour >= 24)hour = 0;for (int i = 1; i <= len; i++)printf("%d : %d\n", i, a[i]);Sleep(1000);//}}}return 0;}

嗯,很好。现在博主发现了BUG:原来是Sleep(1000)太影响读入,于是博主分段成100次读入。这下就基本没有问题啦。

// making by zhouzhuan#include <bits/stdc++.h>#include <Windows.h>using namespace std;#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000)? 1 : 0)     int l, r;int hour, minute, second;void get_timer(){system("cls");printf("------------------计时器------------------\n");printf("                      making by  zhouzhuan\n");//      begin   segmentation time                 endprintf("开始(b) 分割(s) Time : %.2d : %.2d : %.2d 清除(e)\n", hour, minute, second);return ;} int main(){while (true){// initializationint a[10005], len = 0;hour = 0, minute = 0, second = 0;memset(a, 0, sizeof(a));get_timer();// start timerwhile (!KEY_DOWN('B')) ;// get left timel = clock();//printf("%d\n", l);//Sleep(5000);while (true){// end timerif (KEY_DOWN('E'))break;else if (KEY_DOWN('S')){//get right timer = clock();a[++len] = r - l;}get_timer();// next timesecond++;if (second >= 60){minute++;second = 0;} if (minute >= 60){hour++;minute = 0;}if (hour >= 24)hour = 0;for (int i = 1; i <= len; i++){// print timeint _time = a[i] - l;printf("%3d . %.2d:%.2d:%.2d:%.3d\n", i, _time / 3600000 % 60, _time / 60000 % 60, _time / 1000 % 60,_time % 1000);}//printf("------------------------------------------\n");/* quick time :100 * 10 = 1000 ms = 1 s second ++ / 1 s */for (int i = 1; i <= 100; i++){if (KEY_DOWN('S')){// get right timer = clock();// get timeif (r - a[len] > 500)a[++len] = r;}Sleep(10);}}}return 0;}


还是几十行,没什么难度,大佬勿喷。

原创粉丝点击