{ Come leggere i tasti F11 ed F12 ? 
  Beh, non Š dificile: basta usare gli interrupt 16/10 e 16/11 del BIOS.
  Purtroppo le funzioni ReadKey e KeyPressed del Pascal chiamano gli interrupt
  16/00 e 16/01 che scartano alcuni tasti e combinazioni di tasti, tra cui F11
  ed F12.  Le possibilit…, allora, sono due: riscrivere ReadKey e KeyPressed
  utilizzando al loro interno gli interrupt 16/10 e 16/11, oppure modificare
  la ISR dell'INT 16 in modo da forzare l'uso delle funzioni 16/10 e 16/11 al
  posto di 16/00 e 16/01; in questo caso sar… possibile continuare ad usare le
  funzioni ReadKey e KeyPressed incluse nella unit CRT.

  La unit che segue si basa sulla seconda soluzione che Š un po' pi—
  complicata della prima, ma anche pi— interessante. }



Unit F11F12;  { By Pino Navato }

interface

  var EnhKbdAvailable : boolean;


implementation
uses DOS;

var  OldInt16    : procedure;
     OldExitProc : pointer;
     reg         : registers;


procedure ExitHandler; far;  { Automatically restore old vector before exiting }
   begin
      ExitProc := OldExitProc;
      SetIntVec($16, @OldInt16)
   end;


Procedure NewInt16; assembler;
   asm
      push   ds

      push   ax
      mov    ax,seg @Data
      mov    ds,ax      { now ds points to segment containing OldInt16 }
      pop    ax

      pushf             { save flags passed to int 16 (just to be safe) }
      cmp    ah,1       { old read or test keyboard buffer? }
      jna    @1

      popf              { restore original flags before calling OldInt16 }

      pushf
      call   OldInt16   { all other calls }
      jmp    @3

@1:   or     ah,10h     { make it extended }
      popf              { restore original flags before calling OldInt16 }

      pushf
      call   OldInt16

      pushf           { save flags coming from OldInt16 (it's necessary!) }
      cmp    al,0E0h
      jne    @2
      xor    al,al    { remap E0 extended codes to 00 so readkey accepts them }
@2:   popf            { restore flags coming from OldInt16 }
@3:   pop    ds
      retf   2        { return and discard flags from stack (2 bytes) }
   end;



begin  { Initialization }
   EnhKbdAvailable := false;
   if mem[$0040:$0096] and 16 = 16 then   { Check for enhanced keyboard }
      begin
	 reg.ax := $12FF;
	 intr($16,reg);
	 if reg.ax <> $12FF then          { Further check to be safe }
	    begin
	       GetIntVec($16, @OldInt16);
	       SetIntVec($16, @NewInt16);
	       OldExitProc := ExitProc;
	       ExitProc := @ExitHandler;
	       EnhKbdAvailable := true
	    end
      end
end.


{ Questa unit non influenza solo la gestione dei tasti F11 ed F12, bensŤ
  permette di leggere anche molte altre combinazioni di tasti che, normalmente,
  vengono ignorate.  Di seguito sono elencate tali combinazioni insieme ai
  codici restituiti da ReadKey.

	       Plain     Shift     Control   Alt
	       -----     -----     -------   ----
 F11           0085*     0087*     0089*     008B*
 F12           0086*     0088*     008A*     008C*
 Esc             1B        1B        1B      0001*
 Backspace       08        08        7F      000E*
 Tab             09      000F      0094*     00A5*
 Enter           0D        0D        0A      001C*
 Ins           0052      0052      0092*     00A2*
 Del           0053      0053      0093*     00A3*
 Home          0047      0047      0077      0097*
 End           004F      004F      0075      009F*
 PgUp          0049      0049      0084      0099*
 PgDn          0051      0051      0076      00A1*
 Up            0048      0048      008D*     0098*
 Down          0050      0050      0091*     00A0*
 Left          004B      004B      0073      009B*
 Right         004D      004D      0074      009D*
 Pad-Slash       2F        2F      0095*     00A4*  (Pad = tastierino numerico)
 Pad-Asterisk    2A        2A      0096*     0037*
 Pad-Minus       2D        2D      008E*     004A*
 Pad-Plus        2B        2B      0090*     004E*
 Pad-Enter       0D        0D        0A      00A6*
 Pad-Period      2E#     0053#     0093*      n/a
 Pad-0           30#     0052#     0092*      n/a
 Pad-1           31#     004F#     0075        01
 Pad-2           32#     0050#     0091*       02
 Pad-3           33#     0051#     0076        03
 Pad-4           34#     004B#     0073        04
 Pad-5           35#     004C#*    008F*       05
 Pad-6           36#     004D#     0074        06
 Pad-7           37#     0047#     0077        07
 Pad-8           38#     0048#     008D*       08
 Pad-9           39#     0049#     0084        09

Note:
* Codici normalmente non restituiti da ReadKey.
# Scambiare questi codici se il Num Lock Š spento.  }
