home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / pascal / 5152 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  2.1 KB

  1. Path: sparky!uunet!gatech!psuvax1!rutgers!uwvax!zazen!doug.cae.wisc.edu!castlab.engr.wisc.edu!chris
  2. From: chris@castlab.engr.wisc.edu (Christian Rohrmeier)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Read any key from the keyboard?
  5. Message-ID: <1992Sep1.105717.11923@doug.cae.wisc.edu>
  6. Date: 1 Sep 92 15:57:17 GMT
  7. References: <1992Sep1.123402.160@csghsg5a.bitnet>
  8. Organization: U of Wisconsin-Madison College of Engineering
  9. Lines: 53
  10.  
  11. In article <1992Sep1.123402.160@csghsg5a.bitnet> 89612048s@csghsg5a.bitnet writes:
  12. >How to read any key from the keyboard?
  13. >
  14. >Can someone give me an example how to read any key pressed on the
  15. >keyboard. That means also the ALT SHIFT CONTROL and combinations
  16. >of these keys.
  17. >
  18. >And also, can you help me about the Num, Scrol and Capslock keys.
  19. >How to turn them on and off, and how to get there current status?
  20. >
  21. >I want to say thank you very much for your help.
  22. >
  23. >Yours Markus
  24.  
  25. I can answer the 1st part of your question:
  26.  
  27. function getkey:string;
  28.  
  29. begin
  30.   key:=readkey;
  31.   getkey:=key;
  32.   if key= chr(27) then getkey:='esc'
  33.   else if key= #0 then begin
  34.     key:= readkey;
  35.     if key= 'I' then getkey:='pgup'
  36.     else if key= 'Q' then getkey:='pgdn'
  37.     else if key= 'O' then getkey:='end'
  38.     else if key= 'G' then getkey:='home'
  39.     else if key= 'H' then getkey:='up'
  40.     else if key= 'P' then getkey:='down'
  41.     else if key= 'K' then getkey:='left'
  42.     else if key= 'M' then getkey:='rite'
  43.   end;
  44. end;
  45.  
  46. Ok, its not elegant, but it works (use case if you wanna.)
  47. The deal is, any non-normal key will return a #0 value the 1st readkey,
  48. and a letter value the next readkey you do (before anymore keys are hit.)
  49.  
  50. So, looking back of your handy-dandy TP6.0 Programmer's Guide, page 350, will
  51. show you all the other letter equivilencies for all the ALT, CONTROL, and
  52. Function Key combinations.
  53.  
  54. Some keys are not gonna give you the #0 code though, so just check for their
  55. numeric ASCII value with chr(x), as I did in the case of ESC (A complete ASCII
  56. chart is found on page 348).
  57.  
  58. The other way to do this is to do some in-line assembler routine and use the Hex
  59. codes found (conveniently enough) on page 352!
  60.  
  61. Enjoy. 
  62.  
  63. -Chris
  64.