neviatar@ruunsa.fys.ruu.nl (Hadass Eviatar) (11/02/90)
Hi netters, Anyone out there who knows how to read a single keystroke under OS9? The manual tells me to do a read (1, &buffer, 1); ^= # of chars ^= input channel but when I call this function, it reads the first keystroke, puts it in the buffer and waits... It waits until the second key is struck, and then the function returns the information on the first keystroke, and puts the second keystroke in the buffer and waits... Of course, I tried other buffer-lengths than 1 (even zero!), but to no avail. What I need is a procedure that waits for a key to be struck (i.e. either an ASCII character or a function-key) and reports this keystroke IMMEDIATELY (i.e. without waiting for the enter/return key to be hit) to the calling program. If anyone knows how, please let me know. Thanks in advance. ==================================================================== Hadass Eviatar, Dept. of Molecular Biophysics, University of Utrecht Physically: Buys Ballot Laboratory, Princetonpl. 5, 3584 CC Utrecht Electronically: neviatar@ruunsa.fys.ruu.nl Acoustically: 030 - 531555/2839/2951 Always yield to temptation - Oscar Wilde. ====================================================================
dnelson@mthvax.cs.miami.edu (Dru Nelson) (11/02/90)
Did you set your stdin to stop buffering? -- %% Dru Nelson %% Miami, FL %% Internet: dnelson@mthvax.cs.miami.edu %%
pete@wlbr.IMSD.CONTEL.COM (Pete Lyall) (11/03/90)
Actually, when using read() buffering shouldn't come into play. One possibiliy is a _gs_ready loop (no manual here, so this is approximate): while(!_gs_ready(path)) ; /* do nothing */ read(path,&charbuf,1); Pete Lyall -- Pete Lyall Contel Corporation Compuserve: 76703,4230 OS9_Net: (805) 375-1401 (24hr 300/1200/2400) Internet: pete@wlbr.imsd.contel.com UUCP: {hacgate,jplgodo,voder}!wlbr!pete
knudsen@cbnewsd.att.com (michael.j.knudsen) (11/03/90)
In article <1728@ruunsa.fys.ruu.nl>, neviatar@ruunsa.fys.ruu.nl (Hadass Eviatar) writes: > The manual tells me to do a > read (1, &buffer, 1); > ^= # of chars > ^= input channel Try using 0, not 1, as the input channel (stdin, not stdout). I hope that helps. > It waits until the second key is struck, and then the function > returns the information on the first keystroke, and puts the > second keystroke in the buffer and waits... This is weird. But in addition to fixing the channel number, the way to do a non-blocking read is to first use a I$GetSt call to find whether there are any characters waiting in OS9's buffer (not the same as YOUR buffer). If not, go do something else. If so, then read one. Tho maybe you aren't asking for a non-blocking read. Anyway, your read() should always return the latest character, so your problem may well be the wrong channel number. > Of course, I tried other buffer-lengths than 1 (even zero!), > but to no avail. Just one byte long will do. Any more is unused. -- "Round and round the while() loop goes; Whether it stops," Turing says, "no one knows."