在c ++控制台中检测功能键. [英] Detect function keys in c++ console.
本文介绍了在c ++控制台中检测功能键.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测功能键(例如f1)以保存f2以便使用c ++在控制台中刷新,因此我可以添加更多功能.
I want to detect function keys such as f1 to save f2 to refresh in console using c++ so I can add further functionality.
推荐答案
检查此示例:
#include <conio.h>
using namespace std;
int main()
{
cout << "Press any key! CTRL-D to end" << endl;
while(1)
{
unsigned char x = _getch();
if (0 == x)
{
printf("Function key!\n");
x = _getch();
}
printf("key = %02x\n", x);
if (x == 4) break;
}
return 0;
}
当您按下功能键时,将得到一个零,然后是另一个代码.使用该代码确定获得的F键.
When you press a function key, you'll get a zero followed by another code. Use that code to determine which F-key you got.
这篇关于在c ++控制台中检测功能键.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文