home *** CD-ROM | disk | FTP | other *** search
- program Display_Keys;
-
- { This program is placed in the public domain by Steve Wood,
- author of Using Turbo Pascal, published by Osborne/McGraw-Hill.
-
- The program has been modified so that when <Alt><1> is
- pressed interrupt $80 is activated. Before running this
- program an interrupt handler must be installed for
- interrupt $80. This can be done by executing INTR.COM
- program from DOS. Normally this would be done in a start-up
- batch file. See the comments in READ-ME and INTR.PAS for details. }
-
- {$I STD-ATTR.INC}
- {$I STD-CTV.INC}
-
- const INTR_KEY = #120; { Alt-1 }
- INTR_VECTOR = $80; { Identifies the interupt being utilized. }
-
- procedure Intr_80;
- var ms_reg : RegPack;
- xpos, ypos : Byte;
-
- begin
- xpos := WhereX; ypos := WhereY; { Save the cursor position. }
- FillChar(ms_reg,SizeOf(ms_reg),ZERO);
-
- (*The following statements store the address of the first program variable
- in the interrupt vector table at the table position following the actual
- interrupt being used. By doing this you provid a means by which the
- interrupt routine can locate variables used by the calling routine.
- Since all of my programs begin with {$I STD-ATTR.INC} the first variable
- declared is always vid_attr. *)
-
- with ms_reg do
- begin
- ah := $25; al := INTR_VECTOR + 1; ds := Dseg; dx := Ofs(vid_attr);
- end; {with}
- MsDos(ms_reg);
-
- FillChar(ms_reg,SizeOf(ms_reg),ZERO);
- Intr($80,ms_reg); { Activate the interrupt handler at INTR_VECTOR }
- GoToXY(xpos,ypos); { Restore the cursor position upon return. }
- end; { Intr_80 }
-
- procedure Read_Kbd(var inchr,inctl: Char);
- var ms_reg : RegPack;
-
- begin
- inctl := NULL_CHR; { Initialize inctl to NULL_CHR. }
- with ms_reg do
- begin
- ax := ZERO; { ah = 0 for read next kbd char. }
- Intr($16,ms_reg); { Call keyboard interrupt routine. }
- inchr := Chr(al); { Convert result to Char. }
- if (inchr = #0) then { If function/special key pressed }
- begin { get scan code and handle }
- if (Chr(ah) = INTR_KEY) then { interrupt if INTR_KEY pressed. }
- Intr_80;
- inctl := Chr(ah) { Put scan code in inctl. }
- end
- else { Otherwise trap conventional }
- if (inchr in [#1..#31,DEL]) then { control codes as scan codes.}
- inctl := inchr;
- end; {with}
- end; { Read_Kbd }
-
- begin { Display_Keys }
- ClrScr;
- WriteLn('Press a key to display its ASCII Code');
- WriteLn('Press <Alt><1> to invoke interrupt $80');
- WriteLn('Press <CTRL><Q> to QUIT');
- repeat
- Read_Kbd(inchr,inctl);
- if (inchr > #0) then
- WriteLn('The ASCII code for ',inchr,' is ',Ord(inchr));
- if (inctl > #0) and (inchr = #0) then
- WriteLn('The scan code for ',inchr,' is ',Ord(inctl));
- until (inchr = ^Q);
- end. { Display_Keys }
-