Article View: comp.os.msdos.programmer
Article #4299Re: TC++ mouse and F11/F12 detection
From: Asbj|rn St|en
Date: Mon, 21 Jan 1991 00:28
Date: Mon, 21 Jan 1991 00:28
84 lines
3449 bytes
3449 bytes
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 / \ |
| / ___/ |
-------------------------------------------------
Technical Details
Message-ID:
<1991Jan21.002856.22154@ugle.unit.no>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!ugle.unit.no!solan1.solan.unit.no!stoeenReferences:
<1991Jan18.222532.1067@vlsi.polymtl.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!ugle.unit.no!solan1.solan.unit.no!stoeen From: stoeen@solan.unit.no (Asbj|rn St|en) Newsgroups: comp.os.msdos.programmer Subject: Re: TC++ mouse and F11/F12 detection Keywords: Extended keyboard codes Message-ID: <1991Jan21.002856.22154@ugle.unit.no> Date: 21 Jan 91 00:28:56 GMT References: <1991Jan18.222532.1067@vlsi.polymtl.ca> Sender: news@ugle.unit.no Reply-To: stoeen@solan.unit.no (Asbj|rn St|en) Organization: Norwegian Institue of Technology Lines: 84