home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mod201j.zip / modula2.exe / os2src / keys.mod < prev    next >
Text File  |  1995-06-19  |  2KB  |  77 lines

  1. IMPLEMENTATION MODULE Keys;
  2. (*
  3.     Description : Symbolic constants for non-ASCII keyboard functions
  4.     Author      : I.R. Matters (Ian.Matters@anu.edu.au)
  5.     System      : Juergen Neuhoff's Modula-2 compiler on OS/2 v3.0
  6.     Version     : 1.00
  7.     Last Edit   : 19 June 1995
  8.  
  9.     Notes       : The values described in this table assume that the
  10.                   second byte of the keyboard code is shifted by 128
  11.                   decimal where possible.
  12.  
  13.                   Alt-Spacebar is specially mapped to 215C;
  14.                   The Ctrl-2 key is remapped to an ASCII nul;
  15.                   Ctrl-PrintScreen is only supported in full screen mode.
  16. *)
  17.  
  18.  
  19. FROM SYSTEM   IMPORT TSIZE;
  20. FROM Terminal IMPORT GetEcho, SetEcho, Read;
  21. FROM Keyboard IMPORT ScanCode;
  22.  
  23. (*$XL+  Modula-2 language extensions: allowed extended imports *)
  24.  
  25. IMPORT FROM KBD32;
  26.  
  27.  
  28. PROCEDURE GetKeyChar(): CHAR;
  29. (*
  30.    Read a key as a CHAR.  If it's a special key,
  31.    return then second byte with the high bit set.
  32. *)
  33. CONST ASCIInul     =   0C;
  34.       ASCIIetx     =   3C;
  35.       HighBit      =  80H;
  36.       GrayControls = 340C;  (* Prefix for gray arrows and movement keys *)
  37. VAR ch        : CHAR;
  38.     shiftKeys : Modifiers;
  39.     oldFlag   : BOOLEAN;
  40. BEGIN
  41.   GetEcho (oldFlag);
  42.   SetEcho (FALSE);
  43.   Read (ch);
  44.   SetEcho (oldFlag);
  45.   GetModifiers (shiftKeys);
  46.  
  47.   IF ((ch = ASCIInul) OR (ch = GrayControls)) THEN
  48.     ch := CHR (ScanCode());
  49.     IF (ch = ASCIIetx) THEN  (* Remap Ctrl-2 key to ASCIInul *)
  50.       ch := ASCIInul;
  51.     ELSE
  52.       ch := CHR (ORD (ch) OR HighBit);
  53.     END;
  54.   END;  (* IF *)
  55.  
  56.   IF ((ch = ' ') AND (AltKey IN shiftKeys)) THEN  (* Map Alt-Spacebar *)
  57.     ch := AltSpacebar;
  58.   END;
  59.  
  60.   RETURN (ch);
  61. END GetKeyChar;
  62.  
  63.  
  64. PROCEDURE GetModifiers (VAR State: Modifiers);
  65. (*
  66.    Check the status of the various shift and lock keys
  67. *)
  68. VAR rc16    : APIRET16;
  69.     kbdInfo : KBDINFO;
  70. BEGIN
  71.   kbdInfo.Size := TSIZE (KBDINFO);
  72.   rc16 := KbdGetStatus (kbdInfo, 0);
  73.   State := Modifiers (kbdInfo.State);
  74. END GetModifiers;
  75.  
  76.  
  77. END Keys.