我正在尝试创建一个函数,如果用户按下键盘上除大写P以外的任何按钮,将printf一个特定的字符串,如果用户按下P,那么它将中断循环。
然而,我认为我没有正确使用_kbhit和_getch。我使用数字80,因为这是80....sorry的ASCII符号,表示混淆
void activateAlarm(int channelID) {
int key = 0;
while(temperatureChannel[channelID].currentTemperature > temperatureChannel[channelID].highLimit
||temperatureChannel[channelID].currentTemperature < temperatureChannel[channelID].lowLimit) {
beep(350,100);
if (_kbhit()) {
key = _getch();
if(key == 'P');
break;
}
}
}发布于 2013-03-25 03:44:23
不需要解释,代码会说得更好:
#include <conio.h>
// ...
printf("please press P key to pause \n ");
int key = 0;
while(1)
{
if (_kbhit())
{
key =_getch();
if (key == 'P')
break;
}
}https://stackoverflow.com/questions/15603082
复制相似问题