Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!think!snorkelwacker!spdcc!merk!alliant!linus!mbunix!duncant From: duncant@mbunix.mitre.org (Thomson) Newsgroups: comp.sys.amiga.tech Subject: Re: Urgent Help Needed. Message-ID: <81705@linus.UUCP> Date: 4 Dec 89 02:12:18 GMT References: <1083@unsvax.NEVADA.EDU> Sender: news@linus.UUCP Reply-To: duncant@mbunix.mitre.org (Thomson) Organization: The MITRE Corp. Bedford, MA Lines: 50 In article <1083@unsvax.NEVADA.EDU> maniac@arrakis.nevada.edu.uucp (ERIC SCHWERTFEGER) writes: >)... I've got a program that runs from the CLI, and >I need to detect when a key is struck, and what key was struck. > The problem I'm having is that any key I hit is echoed to the >window, which blocks window output, until I press return. > I want a way around this, using standard C functions, that will >work with Lattice 4.0, because this program is going to be ported over >to a Unix environment to be turned in for a class project. > BTW, the method I'm using now is getchar(). I think the problem you are having is actually more accurately described as: input from the keyboard (stdin in this case) is done using line buffering. In this mode, an I/O operation is not completed until a return is pressed (allowing editing of the input line with the backspace key). Therefore your program is sitting there at the getchar() call, waiting for the I/O to complete. The solution SHOULD be to change the buffering mode from line buffering to no buffering, using the standard library function setvbuf(). Unfortunately, this doesn't work. It doesn`t work with a lot of compilers on a lot of systems actually. I'd be interested in hearing from someone close to the C language ANSI comittee if there is a reason for this. Am I interpreting the standard`s description of setvbuf incorrectly? The second problem you may have is you want to get rid of character echo. I'm not sure there is a way to do this in the ANSI C library. Anyone else know of a way? If you're not concerned about portability, you can solve all yourproblems by sending a message to the console handler which puts it into RAW mode. I have some code somewhere which does this. Let me know if you still need it. By the way, i think you can also do something like: FILE *keybd; keybd = fopen( "RAW:", "r" ); c = fgetc( keybd ); ... I tried this once, and it worked - what you're doing is using the console handler in it's raw mode. I'm not quite sure now whether "RAW" is exactly the right name though. (I'm now writing this message in my office using a PC (yuck) and I don't have any amiga manuals or code handy, which is why I'm a but fuzzy on the details) Duncan Thomson