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 INTR.PAS for details. }
-
- {$I STD-ATTR.INC}
-
- const INTR_KEY = #120; { Alt-1 }
- INTR_VECTOR = $80; { Identifies the interupt being utilized. }
- ZERO = 0;
- NULL_CHR = #0;
- ESC = #27;
-
- type RegPack = record
- case Boolean of
- TRUE : (ax,bx,cx,dx,bp,si,di,ds,es,flags : Integer);
- FALSE : (al,ah,bl,bh,clo,chi,dl,dh : Byte);
- end;
-
- var inchr,inctl : Char;
-
- procedure Intr_80;
- var regs : RegPack;
- xpos, ypos : Byte;
-
- begin
- FillChar(regs,SizeOf(regs),ZERO);
-
- (*The following statements store the address of the first global variable
- in the interrupt vector table at the table position following the actual
- interrupt being used. By doing this you provide a means by which the
- interrupt routine can locate global variables used by the calling program.
- Since all of my programs begin with {$I STD-ATTR.INC} the first variable
- declared is always vid_attr. *)
-
- with regs do
- begin
- ah := $25; al := INTR_VECTOR + 1; ds := Dseg; dx := Ofs(vid_attr);
- end; {with}
- MsDos(regs);
-
- Intr($80,regs); { Activate the interrupt handler at INTR_VECTOR }
- end; { Intr_80 }
-
- procedure Read_Kbd(var inchr,inctl: Char);
- var regs : RegPack;
-
- begin
- inctl := NULL_CHR; { Initialize inctl to NULL_CHR. }
- with regs do
- begin
- ax := ZERO; { ah = 0 for read next kbd char. }
- Intr($16,regs); { 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,#127]) 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 or IBM scan code.');
- WriteLn('Press <Alt><1> to activate interrupt $80');
- WriteLn('Press <Esc> 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 = ESC);
- end. { Display_Keys }
-