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()
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).
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?
Check out curses or ncurses, sounds like kind of thing you want to be using.
PDCurses seems to be the Windows option - Is ncurses available for windows?