From: Bart Oldeman (Bart.Oldeman@bristol.ac.uk)
Date: Sun 13 Aug 2000 - 00:58:12 IDT
On Fri, 11 Aug 2000, Lionel Pinkhard wrote: > I'm having a little trouble with the keyboard, I tried your piece of code > (thanks a lot, BTW!), and I include <ncurses.h> as well, and got this > output: > > /tmp/cca020801.o: In function `gameloop': > /tmp/cca020801.o(.text+0x2f2): undefined reference to `noecho' > /tmp/cca020801.o(.text+0x2f7): undefined reference to `cbreak' That's a linking problem. Solved by putting -lncurses on the gcc command line. My loop was a bit wrong anyway, if you want to test for non-blocking input. Better is (with #include <curses.h>): noecho(); cbreak(); /* set cbreak mode (don't wait for return key) */ nodelay(stdscr,TRUE); while ((keypressed=getch())!=ERR) { You see in non-blocking mode, kbhit() is equivalent to getch()!=ERR. But getch also gives you the resulting key so you don't want to loose it. With svgalib instead of ncurses it's easier: while ((keypressed=vga_getkey()) { /*vga_getkey returns zero if no key has been hit*/ Check out raw keyboard mode in svgalib if you need special keys not in the ascii table or ncurses. > Also, I checked out the man page for gettimeofday, I'm just having a > little trouble understanding it, what type of variable should I set up to > store it in? Can you give me an example of how I can get the time from it? > Sorry, the man page is talking about struct's, and I don't have that much > experience with it (well, I've never returned a struct, but I have used > them before). struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); Simple ;-) BUT if you just want to use your timing for a delay you're better of and it's easier using sleep or usleep. (see man 3 sleep or usleep) usleep suspends the execution for the given interval of microseconds. Bart
This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:23 IST