Hello,
Does it exist a similar function to “kbhit( )” ( Watcom / QNX 4 ) on Qnx
6.2 ?
- these function allows to test if a char is available on keyboard without
block the process -.
thanks
Hello,
Does it exist a similar function to “kbhit( )” ( Watcom / QNX 4 ) on Qnx
6.2 ?
thanks
Philippe ELSKENS wrote:
Hello,
Does it exist a similar function to “kbhit( )” ( Watcom / QNX 4 ) on Qnx
6.2 ?
- these function allows to test if a char is available on keyboard without
block the process -.
Yes, select (which is also available on QNX4 - i.e. it is portable).
Here is a trivial example. Should run unaltered on QNX4 or QNX6.
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/select.h>
int raw(int fd)
{
struct termios termios_p;
if(tcgetattr( fd, &termios_p ) )
return( -1 );
termios_p.c_cc[VMIN] = 1;
termios_p.c_cc[VTIME] = 0;
termios_p.c_lflag &= ~( ECHO|ICANON|ISIG|ECHOE|ECHOK|ECHONL );
return(tcsetattr( fd, TCSADRAIN, &termios_p));
}
int main()
{
int n,fd=fileno(stdin);
fd_set rdfds;
struct timeval tv;
raw(fd);
tv.tv_sec=0;
tv.tv_usec=250000;
while(1) {
FD_ZERO(&rdfds);
FD_SET(fd, &rdfds);
switch(n=select(fd+1, &rdfds, NULL, NULL, &tv)) {
case -1:
perror(“select”);
exit(EXIT_FAILURE);
case 0:
printf(“I’m not blocked\n”);
break;
default:
if(FD_ISSET(fd, &rdfds)) {
printf(“you hit %c\n”, getchar());
}
break;
}
}
exit(EXIT_SUCCESS);
}