![]() |
| | #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 | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| getch() equivalent in C++ | hauzer | C++ Programming | 3 | 06-02-2009 05:54 PM |
| Another syntax error | caldeira | C Programming | 31 | 09-05-2008 01:01 AM |
| Wiki FAQ | dwks | General Discussions | 192 | 04-29-2008 01:17 PM |
| kbhit() and getch() Equivalent.. | ThLstN | C Programming | 1 | 03-11-2008 02:44 AM |
| Pls repair my basketball program | death_messiah12 | C++ Programming | 10 | 12-11-2006 05:15 AM |