newbie Q - how to wait for keystroke in gcc/xcode ??

X

xr600

Guest
Hi ...

Is there a worthy GCC alternative to the "getche" command in win/dos c++, I've been searching the web for 3 hours now, and can't really find any solution :/.

The thing is, that I wan't my program to wait for a keystroke (like cin, but without pressing "return")... is there some easy way to do that ??.

Newbie thanX.

Torben.
 
OP
X

xr600

Guest
shadov said:
SDL can do that. But if there is easier solution I'd like to hear about it too.

Yeah !... In a windows/DOS enviroment you would probably use Conio.h, but that's a no go in xcode/GCC. Someone (on another site) mentioned something about ncurses, but I'll be damned if I know how to use it :(.

It really should'nt be that hard... should it ??, and please remember that I'm a complete newbie to C++ (last time I did programming Z80 Assembler code was the hottest ;)).

Regards.

Torben.
 
OP
B

binkley

Guest
xr600 said:
Yeah !... In a windows/DOS enviroment you would probably use Conio.h, but that's a no go in xcode/GCC. Someone (on another site) mentioned something about ncurses, but I'll be damned if I know how to use it :(.

I threw together this test program quickly using curses. The only annoying aspect is that it clears the screen when "initscr()" is called.

Code:
#include <curses.h>
int main() {
  int c;

  initscr();

  c = getch();
  printf("\r\nGot character: %c.\r\n", c);

  return 0;
}

Compile with "gcc getch.c -lcurses". Hope that helps.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top