home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / nicol / sti_keys / sti_keys.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1980-01-01  |  7.5 KB  |  246 lines

  1. unit  STI_KEYS;                             { unit to provide access to all}
  2.                                             { the special keys             }
  3. interface
  4.  
  5. uses Dos;
  6.  
  7. type
  8.   KeyRec = string[3];                       { KeyRec[1] = ascii code        }
  9.                                             { KeyRec[2] = F1 etc            }
  10.                                             { KeyRec[3] = GRPH etc          }
  11.  
  12.  
  13.  
  14. function STI_StopPressed    : boolean;      { check for stop key            }
  15. function STI_CopyPressed    : boolean;      { check for copy key            }
  16. function STI_EscapePressed  : boolean;      { check for escape              }
  17. function STI_ControlPressed : boolean;      { check for control key         }
  18. function STI_CapsPressed    : boolean;      { check for caps key            }
  19. function STI_ShiftPressed   : boolean;      { check for shift key           }
  20. function STI_KanaPressed    : boolean;      { check for kana key            }
  21. function STI_GrphPressed    : boolean;      { check for graph key           }
  22. function STI_NferPressed    : boolean;      { check for nfer key            }
  23. function STI_XferPressed    : boolean;      { check for xfer key            }
  24. function STI_InKey          : char;         { return a single key stroke    }
  25. function STI_InKey2         : KeyRec;       { return GRPH,CTRL,SHIFT combos }
  26. function STI_InKey3         : KeyRec;       { return any combination        }
  27.  
  28. implementation
  29.  
  30. {---------------------------------------------------------------------------}
  31.  
  32. type
  33.   key_type = (STOP_Key,COPY_Key,ESC_Key,CTRL_Key,CAPS_Key,
  34.               SHIFT_Key,KANA_Key,GRPH_Key,NFER_Key,XFER_Key);
  35.   key_table = record
  36.                 n : key_type;
  37.                 g : byte;
  38.                 b : byte;
  39.               end;
  40.  
  41. const
  42.   KT : array[0..9] of key_table = (
  43.                             (n:STOP_Key;    g:12;  b:1),
  44.                             (n:COPY_Key;    g:12;  b:2),
  45.                             (n:ESC_Key;     g:0;   b:1),
  46.                             (n:CTRL_Key;    g:14;  b:16),
  47.                             (n:CAPS_Key;    g:14;  b:2),
  48.                             (n:SHIFT_Key;   g:14;  b:1),
  49.                             (n:KANA_Key;    g:14;  b:4),
  50.                             (n:GRPH_Key;    g:14;  b:8),
  51.                             (n:NFER_Key;    g:10;  b:2),
  52.                             (n:XFER_Key;    g:6;   b:32)
  53.                       );
  54.  
  55. {---------------------------------------------------------------------------}
  56.  
  57. function Scan_KeyCode(group : byte) : byte; { check for a keycode           }
  58.  
  59. Var
  60.   r : registers;
  61.  
  62. begin
  63.   r.ah   := 4;                              { check the key funtion         }
  64.   r.al   := group;
  65.   intr(24,r); {18h}                         { BIOS call                     }
  66.   Scan_KeyCode := r.ah;
  67. end;
  68.  
  69. {---------------------------------------------------------------------------}
  70.  
  71. function SpecialKeyPressed(K : key_type) : boolean;
  72.  
  73. begin
  74.   if Scan_KeyCode(KT[ord(k)].g) and KT[ord(k)].b <> 0 then
  75.     SpecialKeyPressed := TRUE
  76.   else
  77.     SpecialKeyPressed := FALSE;
  78. end;
  79.  
  80. {---------------------------------------------------------------------------}
  81.  
  82. function STI_StopPressed : boolean;
  83.  
  84. begin
  85.   STI_StopPressed := SpecialKeyPressed(STOP_Key);
  86. end;
  87.  
  88. {---------------------------------------------------------------------------}
  89.  
  90. function STI_CopyPressed : boolean;
  91.  
  92. begin
  93.   STI_CopyPressed := SpecialKeyPressed(COPY_Key);
  94. end;
  95.  
  96. {---------------------------------------------------------------------------}
  97.  
  98. function STI_EscapePressed : boolean;
  99.  
  100. begin
  101.   STI_EscapePressed := SpecialKeyPressed(ESC_Key);
  102. end;
  103.  
  104. {---------------------------------------------------------------------------}
  105.  
  106. function STI_ControlPressed : boolean;
  107.  
  108. begin
  109.   STI_ControlPressed := SpecialKeyPressed(CTRL_Key);
  110. end;
  111.  
  112. {---------------------------------------------------------------------------}
  113.  
  114. function STI_CapsPressed : boolean;
  115.  
  116. begin
  117.   STI_CapsPressed := SpecialKeyPressed(CAPS_Key);
  118. end;
  119.  
  120. {---------------------------------------------------------------------------}
  121.  
  122. function STI_ShiftPressed : boolean;
  123.  
  124. begin
  125.   STI_ShiftPressed := SpecialKeyPressed(SHIFT_Key);
  126. end;
  127.  
  128. {---------------------------------------------------------------------------}
  129.  
  130. function STI_KanaPressed : boolean;
  131.  
  132. begin
  133.   STI_KanaPressed := SpecialKeyPressed(KANA_Key);
  134. end;
  135.  
  136. {---------------------------------------------------------------------------}
  137.  
  138. function STI_GrphPressed : boolean;
  139.  
  140. begin
  141.   STI_GrphPressed := SpecialKeyPressed(GRPH_Key);
  142. end;
  143.  
  144. {---------------------------------------------------------------------------}
  145.  
  146. function STI_NferPressed : boolean;
  147.  
  148. begin
  149.   STI_NferPressed := SpecialKeyPressed(NFER_Key);
  150. end;
  151.  
  152. {---------------------------------------------------------------------------}
  153.  
  154. function STI_XferPressed : boolean;
  155.  
  156. begin
  157.   STI_XferPressed := SpecialKeyPressed(XFER_Key);
  158. end;
  159.  
  160. {--------- Read a character from the Keyboard (No Display) -----------------}
  161.  
  162. Function  STI_InKey : Char;
  163.  
  164. var
  165.   regs : registers;
  166.  
  167. begin
  168.   regs.ah := $03;
  169.   intr($18,regs);
  170. {  regs.ah := $41;  }                       { this causes problems with the }
  171. { intr($18,regs);   }                       { TP graphics unit              }
  172.   regs.ah := 00;
  173.   intr($18,regs);
  174.   STI_InKey := char(regs.al);
  175. end;
  176.  
  177. {---------------------------------------------------------------------------}
  178.  
  179. function  STI_InKey2 : KeyRec;             { this only checks for CAPS,GRPH }
  180.                                            { and CTRL                       }
  181. var
  182.   DumB   : byte;
  183.   Dummy  : KeyRec;
  184.   regs   : registers;
  185.  
  186. begin
  187.   Dummy := #0#0#0;
  188.   regs.ah := $03;
  189.   intr($18,regs);
  190. {  regs.ah := $41;}                         { causes problems with the      }
  191. { intr($18,regs); }                         { graphics unit in TP           }
  192.   regs.ah := 00;
  193.   intr($18,regs);
  194.   Dummy[1] := char(regs.al);                { assign lo byte to Dummy[1]    }
  195.   if Dummy[1] = #0 then
  196.     Dummy[2] := char(regs.ah);              { this is the extended code     }
  197.   DumB := 0;
  198.   if STI_ControlPressed then inc(DumB,1);
  199.   if STI_ShiftPressed   then inc(DumB,10);
  200.   if STI_GrphPressed    then inc(DumB,100);
  201.   Dummy[3] := char(DumB);
  202.   STI_InKey2 := Dummy;
  203. end;
  204.  
  205. {---------------------------------------------------------------------------}
  206.  
  207. function  STI_InKey3 : KeyRec;             { this checks for everything     }
  208.  
  209. var
  210.   DumB   : byte;
  211.   Dummy  : KeyRec;
  212.   regs   : registers;
  213.  
  214. begin
  215.   Dummy := #0#0#0;
  216.   regs.ah := $03;
  217.   intr($18,regs);
  218. {  regs.ah := $41;}                         { causes problems with the      }
  219. { intr($18,regs); }                         { graphics unit in TP           }
  220.   regs.ah := 00;
  221.   intr($18,regs);
  222.   Dummy[1] := char(regs.al);                { assign lo byte to Dummy[1]    }
  223.   if Dummy[1] = #0 then
  224.     Dummy[2] := char(regs.ah);              { this is the extended code     }
  225.   DumB := 0;
  226.   if STI_ControlPressed then inc(DumB,1);
  227.   if STI_StopPressed    then inc(DumB,2);
  228.   if STI_CopyPressed    then inc(DumB,3);
  229.   if STI_EscapePressed  then inc(DumB,4);
  230.   if STI_CapsPressed    then inc(DumB,5);
  231.   if STI_KanaPressed    then inc(DumB,6);
  232.   if STI_NferPressed    then inc(DumB,7);
  233.   if STI_XferPressed    then inc(DumB,8);
  234.   if STI_ShiftPressed   then inc(DumB,10);
  235.   if STI_GrphPressed    then inc(DumB,100);
  236.   Dummy[3] := char(DumB);
  237.   STI_InKey3 := Dummy;
  238. end;
  239.  
  240. {---------------------------------------------------------------------------}
  241.  
  242. begin
  243. end.
  244.  
  245.  
  246.