[comp.os.msdos.programmer] TC++ mouse and F11/F12 detection

stoeen@solan.unit.no (Asbj|rn St|en) (01/21/91)

  Paul Do (News) asks:

> on another subject, I'd like to be able to detect the F11 and F12
> keys in my Turbo Pascal programs.  I tried using 'getch' in TC++ and
> so far I have mixed results:  on some keyboards/AT, I detect a key
> but on some other configurations, it is as if the F11 key is just
> for decorations!  I suspect it is a BIOS dependent thing...
 
Yes, it is highly BIOS dependent, but the problem can be solved
quite easily. The BIOS has two different calls for handling the
keyboard, one for the old XT keyboards and one for AT keyboards.
Here are some assembly language routines you could use.

CODE    SEGMENT PUBLIC 'CODE'
	Assume CS:CODE, DS:CODE

PUBLIC  My_ReadKey
PROC    My_ReadKey FAR
	mov  al,cs:[buffer]     ; Extended keys are being processed
	or   al,al		; in two steps, first returning 0 then
	jnz  label1		; returning the scan code of the key.
	mov  ah,10h		; Function 10h reads an AT keyboard while
	int  16h		; function 00h reads an XT keyboard.
	or   al,al
	jnz  label1
	mov  cs:[buffer],ah
label1: ret
buffer: db   0
ENDP    My_ReadKey	
     
PUBLIC  My_KeyPressed
PROC    My_KeyPressed FAR
	mov  ah,11h		; The corresponding XT keyboard
	int  16h		; function is 01h.
	mov  ax,0FFFFh          ; Assume true
  	jnz  label2		; Zero flag is clear if there is a
	inc  ax			; waiting key.
label2:	ret
ENDP	My_KeyPressed


Of course, this may not be fully satisfactory, since these
function aren't compatible with XT keyboards. I do not
guarantee the following, but I think you can make the code work
on most machines by replacing the 'int 16h' instruction with
'call general_int_16'.

PROC	general_int_16 FAR
	mov  al,ah
	mov  ah,92h		; Illegal function number. The maximum
	int  16h		; function number is subtracted from
	sub  ah,80h		; this value. Use this to calculate the
	sub  al,ah		; correct function number.
	mov  ah,al
	int  16h
	ret
ENDP	general_int_16


This code could be assembled by MASM or TASM (in MASM mode).
If you don't have these, try to use debug to read in the code,
then see what codes are being generated, and then put these
into an inline statement. Functions should be compiled with the
far call switch {$F+} on. The syntax is (if you have written
the routines into filename.ASM):

{$F+}
function My_ReadKey:char; external;
function My_KeyPressed:boolean; external;
{$L filename.OBJ}
{$F-}

I hope that this can be of some help. I haven't tested it myself,
so I guess there are about four or five bugs in this program.

-------------------------------------------------
|				_		|
|Asbjoern Stoeen	       / \     /___	|
|Studpost 188	              /___\   //	|
|7034 Trondheim-NTH	     / 	   \ / \__	|
|Norway				    /     \	|
|	                           /   ___/	|
-------------------------------------------------