Article View: comp.os.os2.programmer
Article #2889Re: Where is getch()?!??
From: Bruce Kitchin
Date: Wed, 16 Dec 1992 18:05
Date: Wed, 16 Dec 1992 18:05
50 lines
2254 bytes
2254 bytes
david j. looney (me41@sdcc12.ucsd.edu) wrote:
: Speaking of which, for us lowly gnu (golly its not kansas) gcc
: folks, is there ANY workaround in character mode to read single
: characters from the keyboard ala getch() ? Do more recently updated
: libs support this function? Can one call a supplied vio or pm
: functions from a window compatible program ?
:
If your program is not a PM program, you should be able to use the KbdCharIn
function to do what you want. You might even write a getch() which contains
the call to KbdCharIn. Unfortunately, KbdCharIn is not documented in
any of the .Inf files with the 2.0 toolkit. It is a 1.x API function
that is still supported (so why no documentation??). If you don't have
access to a 1.x API document, Ray Duncan's book Advanced OS/2 programming
as well as several other OS/2 programming books (those not targeted for
PM programming) will have it. The call requires a handle returned
by KbdOpen. All the applications in which I have used it are single
threaded on the keyboard so I have a static variable (private to the
module containing getch() or whatever you call it) that is initialized
to something illegal (-1 I think works) and then I do a KbdOpen only
if that initial value is still present and store the returned handle
in the variable.
I haven't tested this, but something like this might work:
#define INCL_KBD
#include <os2.h>
static HKBD hKbd = 0xFFFF;
char getch(void)
{
KBDKEYINFO info;
if(hKbd == 0xFFFF) [
KbdOpen(&hKbd);
KbdGetFocus(IO_WAIT,hKbd);
}
KbdCharIn(&info,IO_WAIT,hKbd);
return (char)(info.chChar);
}
Some examples I've seen use 0 for hKbd without opening it or doing
a get focus on it. This might be defined to work, but I don't know
if it is reliable.
Good luck.
Technical Details
Message-ID:
<1gnr5eINNo2r@hpscit.sc.hp.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!caen!sdd.hp.com!hpscit.sc.hp.com!kitchinReferences:
<42629@sdcc12.ucsd.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!sdd.hp.com!hpscit.sc.hp.com!kitchin From: kitchin@lf.hp.com (Bruce Kitchin) Newsgroups: comp.os.os2.programmer Subject: Re: Where is getch()?!?? Date: 16 Dec 1992 18:05:34 GMT Organization: Hewlett Packard Santa Clara Site Lines: 50 Message-ID: <1gnr5eINNo2r@hpscit.sc.hp.com> References: <42629@sdcc12.ucsd.edu> NNTP-Posting-Host: eden.avo.hp.com X-Newsreader: TIN [version 1.1.2 PL7]