c语言怎么每隔1秒执行一段程序,并保持检测键盘有什么键被按下 - 爱问答

(爱问答)

c语言怎么每隔1秒执行一段程序,并保持检测键盘有什么键被按下

最好附上容易移植的伪代码,谢谢

c语言的定时与键盘与系统或平台有关,不存在容易移值(如单片机的定时与键盘程序肯定不能用于windows的)

以下是Windows的一个程序 ,每秒定时,并判按键,ESC退出程序

#include <conio.h>
#include <windows.h>
#include <stdio.h>
static BOOL bExitApp = FALSE;
const  UINT uiTimerID = 10;
int ct=0;
VOID CALLBACK FooTimerFun( HWND h, UINT u , UINT u1, Dword  d)
{
char c;
printf("%d second ",ct++);
if (kbhit()) {
 c=getch();
 if (c==27)
  bExitApp=TRUE;
 printf("%d key get ",c);

}
}
int main()
{
MSG msgFoo;
SetTimer( NULL , uiTimerID , 1000 , FooTimerFun );
while( !bExitApp && GetMessage( &msgFoo , NULL , 0 , 0 ) ) {
 TranslateMessage( &msgFoo );
 DispatchMessage( &msgFoo );
}
KillTimer( NULL , uiTimerID );
return 0;
}


相关标签:c语言

下一篇:MasterCAMx5程序如何转化为几何图形

上一篇:在String对象中,如何得到一个指定字符的下标

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?