In Linux, The getch () mechanism seems to have to press enter to capture the pressed keys, but because I want to press keypad without entering keys, so I have been stuck there with a program that was originally stored in DOS. It was very simple to compile the program. It took a long time in Linux .... -_-"
Finally, we should find the solution method. We need to reset some of terminal's attention to make it available to our functions ....
Program example:
# Include <termios. h>
# Include <unistd. h>
# Include <assert. h>
# Include <string. h>
/*------------------------------------------------*/
Int getch (void ){
Int C = 0;
Struct termios org_opts, new_opts;
Int res = 0;
// ----- Store old settings -----------
Res = tcgetattr (stdin_fileno, & org_opts );
Assert (RES = 0 );
// ---- Set new terminal parms --------
Memcpy (& new_opts, & org_opts, sizeof (new_opts ));
New_opts.c_lflag & = ~ (Icanon | echo | echoe | echok | echonl | echoprt | echoke | icrnl );
Tcsetattr (stdin_fileno, tcsanow, & new_opts );
C = getchar ();
// ------ Restore old settings ---------
Res = tcsetattr (stdin_fileno, tcsanow, & org_opts );
Assert (RES = 0 );
Return (C );
}