[英]Is there a better way to analyze the key which was pressed without printing on the screen in C (eg. Arrow keys and Return)?
Code snippet (Full code here.) : 代码段(此处为完整代码。) :
int Process (void)
{
for (;;)
{
unsigned char Char_Fore = getch();
if (Char_Fore == 0xE0)
{
unsigned char Char_Back = getch();
switch (Char_Back)
{
case 0x48:
Up();
break;
case 0x50:
Down();
break;
}
}
else if (Char_Fore == 0x0D)
Enter();
}
return 0;
}
This code can run properly on some machine, but some can't because of the getch()
function. 这段代码可以在某些机器上正常运行,但有些因为
getch()
函数而无法运行。
getch()
or _getch()
is a function declared in conio.h
, and the return value would vary if your keyboard is not IBM set 2, or the different compiler were chosen (not Mingw-gcc). getch()
或_getch()
是在conio.h
声明的函数,如果键盘不是IBM set 2,或者选择了不同的编译器(不是Mingw-gcc),返回值会有所不同。
Is there a better way to analyze the key which was pressed in C without printing on the screen and without using a deprecated function like getch()
or _getch()
in console ? 是否有更好的方法来分析在C中按下的键而不在屏幕上打印并且在控制台中不使用像
getch()
或_getch()
这样的弃用函数?
I know this isn't really an answer, but I don't have enough reputation to comment. 我知道这并不是真正的答案,但我没有足够的声誉来发表评论。
I recall using a header called termios.h, and using it I could turn off echoing of characters, now this was on a UNIX system, but I'd imagine there's a Windows equivalent. 我记得使用一个名为termios.h的标题,并使用它我可以关闭字符回显,现在这是在UNIX系统上,但我想有一个Windows等价物。
Here's the pressanykey code with windows.h, perhaps you could adjust it to your needs? 这是windows.h的pressanykey代码,也许您可以根据需要进行调整? http://www.cplusplus.com/forum/articles/7312/#msg33734
http://www.cplusplus.com/forum/articles/7312/#msg33734
Check out curses or ncurses , sounds like kind of thing you want to be using. 查看curses或ncurses ,听起来像你想要使用的东西。
PDCurses seems to be the Windows option - Is ncurses available for windows? PDCurses似乎是Windows选项 - ncurses是否可用于Windows?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.