keyscan wanted

Eric Smith eric at tccc0.UUCP
Wed Jun 7 13:16:45 AEST 1989


>int key_pressed()
>{
>	int mask=1;
>	struct timeval wait;
>
>	wait.tv_sec=0;
>	wait.tv_usec=0;
>	return (select(1,&mask,0,0,&wait));
>}

For that to work reliably, you must make sure the stdin buffer is empty
before calling key_pressed, because the select call doesn't check for
characters already in the stdin buffer.  In some applications using raw
mode this could be very hard to debug unless you had some hints (such as
this one) because an undetected character in the stdin buffer might only
happen very rarely and randomly.  To check for characters in the stdin
buffer, you can look at stdin->_cnt, which tells how many characters,
so it should be 0 to proceed with the key_pressed call.



More information about the Comp.unix.questions mailing list