Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you get a SINGLE character read?

35 views
Skip to first unread message

Robert Gatlin

unread,
Sep 28, 1992, 12:43:47 PM9/28/92
to
I am writting a program in C (Lattice) and need to read a single
character from the keyboard without having to wait for the user
to hit <CR>. I have tried to use the ansii getc() function, but
obviously waits for a <CR>. The I*M version of Turbo C has a
non-ansii standard function getch() which does what I want. Is
a similar function or workaround available for Amiga C?

--
| Robert Gatlin - Supercomputer Interconnect Components - Intel Corporation |
| gat...@scic.intel.com ...!any-MX-mailer-like-uunet!scic.intel.com!gatlin |
______ _ ________ _ __ _
/ _____\ / \ __ __| | | |\ | |
| / / _ \ | | | | | | \ | |
| | ____/ /_\ \ | | | | | |\ \| |
| | |__ | ___ \| | | | | ||\ \ |
| \____/ | / \ \ | | |___| || \ |

Juergen Weinelt

unread,
Sep 30, 1992, 1:55:00 PM9/30/92
to
In article <1992Sep28.1...@scic.intel.com> gat...@scic.intel.com (Robert Gatlin) writes:
>I am writting a program in C (Lattice) and need to read a single
>character from the keyboard without having to wait for the user
>to hit <CR>. I have tried to use the ansii getc() function, but
>obviously waits for a <CR>. The I*M version of Turbo C has a
>non-ansii standard function getch() which does what I want. Is
>a similar function or workaround available for Amiga C?

Sure. Open a "RAW:" window, and use Read() from dos.library.
BTW, I think there's a special escape sequence for turning a
normal "CON:"-window (e.g. the AmigaShell) into a "RAW:" window.

If you need more info, mail me.

>| Robert Gatlin - Supercomputer Interconnect Components - Intel Corporation |
>| gat...@scic.intel.com ...!any-MX-mailer-like-uunet!scic.intel.com!gatlin |

-- Juergen

o _ Juergen Weinelt, Germany
| (_) \/\/ UUCP: swb.de!imart!hcast!jow
' CBMNET: j...@hcast.adsp.sub.org

Doug Walker

unread,
Oct 1, 1992, 9:30:12 AM10/1/92
to

In article <jow....@hcast.adsp.sub.org>, j...@hcast.adsp.sub.org (Juergen Weinelt) writes:
|> In article <1992Sep28.1...@scic.intel.com> gat...@scic.intel.com (Robert Gatlin) writes:
|> >I am writting a program in C (Lattice) and need to read a single
|> >character from the keyboard without having to wait for the user
|> >to hit <CR>. I have tried to use the ansii getc() function, but
|> >obviously waits for a <CR>. The I*M version of Turbo C has a
|> >non-ansii standard function getch() which does what I want. Is
|> >a similar function or workaround available for Amiga C?

Check out RawIO on Fred Fish disk #85 (Yes, 85). It contains
source to a function to change the console window to raw mode
based on a Lattice C filehandle. This still works with Lattice
and SAS/C version 5.x. Under 6.0, functions are provided in the
library to do this.

--
*****
=*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
*|. o.| || 1200/2400/9600 Dual
| o |// For all you do, this bug's for you!
======
usenet: wal...@unx.sas.com bix: djwalker
Any opinions expressed are mine, not those of SAS Institute, Inc.

Rick Morrow

unread,
Oct 2, 1992, 8:12:26 AM10/2/92
to
In article <1992Sep28.1...@scic.intel.com> gat...@scic.intel.com (Robert Gatlin) writes:
>I am writting a program in C (Lattice) and need to read a single
>character from the keyboard without having to wait for the user
>to hit <CR>. I have tried to use the ansii getc() function, but
>obviously waits for a <CR>. The I*M version of Turbo C has a
>non-ansii standard function getch() which does what I want. Is
>a similar function or workaround available for Amiga C?


Here is a simple little routine that I use to get a 'hotkey' type of
response. Because of the use of the SetMode() function this routine is
effectively 2.x only.

----------------------------[ cut ]----------------------------------------

char GetHotKey()
{
BPTR FH;
char c;

FH=Input(); /* find stdin */

SetMode(FH, 1); /* switch stdin to RAW: mode (v36+) */

if(WaitForChar(FH, 0)) /* if there is a character available right away get */
{ /* it, otherwise don't wait. NOTE** there are problems */
/* with WaitForChar() with a timeout of 0 under 1.2/1.3 */

Read(FH, &c, 1); /* get waiting character */
}
else c=0;

return(c); /* return character if one was waiting, or 0 if none */
}


----------------------------[ cut ]----------------------------------------


I've found no problems with switching stdin to RAW: and not switching it
back, but you can switch it back to CON: before the return(c) if you like.
Also, there doesn't seem to be any problems with switching it to RAW:
every time, and since we _have_ to have it in RAW: for this to work, and
anything else can switch it to CON: then we have to switch it to make sure
we know its state.

Hope this proves helpful...

>--
>| Robert Gatlin - Supercomputer Interconnect Components - Intel Corporation |
>| gat...@scic.intel.com ...!any-MX-mailer-like-uunet!scic.intel.com!gatlin |
> ______ _ ________ _ __ _
> / _____\ / \ __ __| | | |\ | |
>| / / _ \ | | | | | | \ | |
>| | ____/ /_\ \ | | | | | |\ \| |
>| | |__ | ___ \| | | | | ||\ \ |
>| \____/ | / \ \ | | |___| || \ |

--
+-------------------------------------+
/ Rick Morrow - r...@delfax.ocunix.on.ca \
<----------------------------------------->
\ North Bay - Ontario - Canada /
+-------------------------------------+

Klaus Seistrup

unread,
Oct 2, 1992, 3:00:40 PM10/2/92
to

Hi Juergen.

[30-Sep-92: Weinelt/All]

>> I am writting a program in C (Lattice) and need to read a single
>> character from the keyboard without having to wait for the user to hit
>> <CR>. I have tried to use the ansii getc() function, but obviously
>> waits for a <CR>. The I*M version of Turbo C has a non-ansii standard
>> function getch() which does what I want. Is a similar function or
>> workaround available for Amiga C?

JW> Sure. Open a "RAW:" window, and use Read() from dos.library. BTW, I
JW> think there's a special escape sequence for turning a normal
JW> "CON:"-window (e.g. the AmigaShell) into a "RAW:" window.

I'm new to this echo, so excuse me if I'm off-topic... But if you're running 2.
0+ the following code might do the trick:

#define CON 0L
#define RAW 1L

long
getch(void)
{
long c;
BPTR fh = Input();

SetMode(fh,RAW);
c = FGetC(fh);
SetMode(fh,CON);

return(c);
}

This has been tested and it works. If somebody out there wants a 1.3-version,
please contact me by E-Mail. :-)


Bliss!

/\ : *** Magnetic Ink *** . FidoNet 2:230/119
/ Klaus Seistrup @ : Ahornsgade 8A, 1.TH. -*- Tel: +45 35-372-171
/____\ : DK-2200 Copenhagen N | AmigaNet 39:141/110

* "Walking back through the hills of dry grass - coming upriver" *

---

0 new messages