vVv - Keypresses (again) [Archive] - C Board

PDA

View Full Version : vVv - Keypresses (again)


Skarr
07-29-2002, 12:45 PM
Hi vVv

Thanks for the function you posted earlier on keypresses. It does, however only work once in my program, the rest of the function calls are just ignored. D'you know how to fix that ('cause I'm lost).

Thanks in advance

Skarr

vVv
07-29-2002, 04:00 PM
Hey,
can you post how you are using it in your code? Note that some special characters, such as the arrow keys, fx, etc are being received with scancode mumbo jumbo.

Skarr
08-01-2002, 08:06 AM
I just tested it in a program like:

#include <stdio.h>

char inchar(void);

// The function here

int main(void) {

printf("%c\n", inchar());

printf("%c\n", inchar());

return 0;

}

And it only works the first time, the second is just skipped.

moi
08-01-2002, 08:48 AM
since you did not post the code for inchar(), i can only assume you expect a personal answer from vVv, which makes this thread useless to everyone else.

Skarr
08-02-2002, 03:02 AM
#include <termios.h>

char inchar()
{
char c;
static struct termios o, n;
tcgetattr( STDIN_FILENO, &o );
cfmakeraw( &n );
tcsetattr( STDIN_FILENO, TCSANOW, &n );
c = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &o );
ungetc( c, stdin );
return c;
}

Here ya go.

Oh, and btw vVv, I'm not trying to scan for arrow keys, just normal letters.

vVv
08-02-2002, 08:47 AM
Either remove the ungetc(), or read the data from stdin after calling ``inchar()''.

printf( "%c\n", inchar() );
getchar();
printf( "%c\n", inchar() );

Skarr
08-06-2002, 06:01 AM
Yeah, but that takes out the meaning of the whole function, doesn't it?