home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / os2 / programm / 7067 < prev    next >
Encoding:
Text File  |  1992-12-16  |  2.1 KB  |  63 lines

  1. Path: sparky!uunet!caen!sdd.hp.com!hpscit.sc.hp.com!kitchin
  2. From: kitchin@lf.hp.com (Bruce Kitchin)
  3. Newsgroups: comp.os.os2.programmer
  4. Subject: Re: Where is getch()?!??
  5. Date: 16 Dec 1992 18:05:34 GMT
  6. Organization: Hewlett Packard Santa Clara Site
  7. Lines: 50
  8. Message-ID: <1gnr5eINNo2r@hpscit.sc.hp.com>
  9. References: <42629@sdcc12.ucsd.edu>
  10. NNTP-Posting-Host: eden.avo.hp.com
  11. X-Newsreader: TIN [version 1.1.2 PL7]
  12.  
  13. david j. looney (me41@sdcc12.ucsd.edu) wrote:
  14. : Speaking of which, for us lowly gnu (golly its not kansas) gcc
  15. : folks, is there ANY workaround in character mode to read single
  16. : characters from the keyboard ala getch() ? Do more recently updated
  17. : libs support this function? Can one call a supplied vio or pm
  18. : functions from a window compatible program ?
  19.  
  20. If your program is not a PM program, you should be able to use the KbdCharIn
  21. function to do what you want.  You might even write a getch() which contains
  22. the call to KbdCharIn.  Unfortunately, KbdCharIn is not documented in
  23. any of the .Inf files with the 2.0 toolkit.  It is a 1.x API function
  24. that is still supported (so why no documentation??).  If you don't have
  25. access to a 1.x API document, Ray Duncan's book Advanced OS/2 programming
  26. as well as several other OS/2 programming books (those not targeted for
  27. PM programming) will have it.  The call requires a handle returned
  28. by KbdOpen.  All the applications in which I have used it are single
  29. threaded on the keyboard so I have a static variable (private to the
  30. module containing getch() or whatever you call it) that is initialized
  31. to something illegal (-1 I think works) and then I do a KbdOpen only
  32. if that initial value is still present and store the returned handle
  33. in the variable.
  34.  
  35. I haven't tested this, but something like this might work:
  36.  
  37. #define INCL_KBD
  38. #include <os2.h>
  39.  
  40. static HKBD hKbd = 0xFFFF;
  41.  
  42. char getch(void)
  43. {
  44.     KBDKEYINFO info;
  45.  
  46.     if(hKbd == 0xFFFF) [
  47.  
  48.             KbdOpen(&hKbd);
  49.         KbdGetFocus(IO_WAIT,hKbd);
  50.         }
  51.  
  52.     KbdCharIn(&info,IO_WAIT,hKbd);
  53.  
  54.     return (char)(info.chChar);
  55.  
  56. Some examples I've seen use 0 for hKbd without opening it or doing
  57. a get focus on it.  This might be defined to work, but I don't know
  58. if it is reliable.
  59.  
  60. Good luck.
  61.