![]() |
| | #1 |
| Lead Moderator Join Date: Aug 1998
Posts: 2,568
| FAQ: Is there a getch() (from conio) equivalent on Linux/UNIX? A: No. But it's easy to emulate: code:-------------------------------------------------------------------------------- Code: #include <stdio.h>
#include <termios.h>
#include <unistd.h>
int mygetch( ) {
struct termios oldt,
newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}--------------------------------------------------------------------------------
There's also a ``getch()'' function in the curses library, but it is /not/ equivalent to the DOS ``getch()'' and may only be used within real curses applications (ie: it only works in curses ``WINDOW''s).. Thanks to VvV for writing this. |
| kermi3 is offline |
| Thread Tools | |
| Display Modes | |
|
|