Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!seismo!beno!black From: black@beno.CSS.GOV (Mike Black) Newsgroups: comp.sys.amiga.programmer Subject: Re: Consoles & RastPorts, and ne'er the twain shall meet Summary: Source for single key stdin input Keywords: stdio Message-ID: <49605@seismo.CSS.GOV> Date: 6 May 91 11:38:39 GMT References: <1991Apr29.221442.14665@bilver.uucp> <30094@dime.cs.umass.edu> Sender: usenet@seismo.CSS.GOV Distribution: na Organization: Center for Seismic Studies, Arlington, VA Lines: 59 Here's what I use for single keystroke handling from stdin: /* Works with Manx 5.0d */ #include #include #include #ifdef DEBUGCON main() { int c=0; setraw(); while(c==0) { puts("Waiting"); c=getch(); } fflush(stdin); printf("\nc=%c\n",c); setrawoff(); } #endif int chkget() /* returns 1 if char available else returns 0 */ { struct _dev *refp; refp = _devtab + stdin->_unit; if(WaitForChar(refp->fd,1)) return 1; return 0; } int getch() /* returns char from stdin if available else returns 0 */ { char c=0; struct _dev *refp; refp = _devtab + stdin->_unit; if(WaitForChar(refp->fd,1)) c=getchar(); return c; } setraw() /* puts stdin in RAW mode */ { struct sgttyb stty; ioctl(fileno(stdin),TIOCGETP,&stty); stty.sg_flags |= RAW; ioctl(fileno(stdin),TIOCSETP,&stty); } setrawoff() /* turns RAW mode off on stdin */ { struct sgttyb stty; ioctl(fileno(stdin),TIOCGETP,&stty); stty.sg_flags &= ~RAW; ioctl(fileno(stdin),TIOCSETP,&stty); } -- ------------------------------------------------------------------------------- : usenet: black@beno.CSS.GOV : land line: 407-494-5853 : I want a computer: : real home: Melbourne, FL : home line: 407-242-8619 : that does it all!: -------------------------------------------------------------------------------