Article View: comp.lang.pascal.borland
Article #459Re: ASCII Codes...
From: Osmo Ronkanen
Date: Fri, 18 Sep 1998 00:00
Date: Fri, 18 Sep 1998 00:00
249 lines
7326 bytes
7326 bytes
In article <Y36aWFAoLVA2Ywpv@pedt.demon.co.uk>,
Pedt Scragg <newsmaster@pedt.demon.co.uk> wrote:
>
>AT (286 machines) and above usually have enhanced BIOS which, with the
>new sub-function $10, can detect these enhanced keycodes.
>
>Although there are *probably* very few pre-AT machines and BIOS's around
>nowadays, I use the unit code following (rather snipped) to auto-detect
>and provide extended support.
>
>Note that some of the codes use $E0 (dec. 224) to indicate some of the
>extended codes.
Not also that 224 is a valid extended ASCII code (alpha) that can be
produced with alt-keypad. So one has to inspect the scan code as well
before one can tell if it is extended function key or alpha character.
>
>I've rewritten this using Intr calls for those with earlier than TP6
>versions that no not accept inline assembler.
>
>Keycode returns both codes at once (unlike readkey that needs two reads
>for extended keystrokes).
>
I chose a different solution, I decided to keep the readkey/keypressed
interface. The unit initialization should check if the extended keyboards
is supported. I cannot guarantee that it works OK so ideally if one
wants compatibility with all keyboards one might offer some way to
override the detection either way (compare this to the use of 87
environment variable by TP programs). Also a good behavior is not to
make F11, F12 or any other extended key a sole way to invoke a critical
function, you might end up running the code with a keyboard that has no
or 11 or F12. For example if one uses only the plain function keys and
not Alt-Fkey combinations, one might duplicate the behavior of F11 in
Alt-F1 and F12 in alt F2, like:
Case scancode of
F1:...
F2:...
...
F11,Alt_F1: ...
F12,Alt_F2: ...
Note that as the unit defines some constants that may be already been
defined in some other units, like "left" and "right", it may be good to
use it early in the list when you incorporate it into an existing
program. However, use it after the CRT.
----
Unit F1112;
interface
var extended_kbd:boolean; { Set to false if no extended support. }
function readkey:char;
function keypressed:boolean;
{* = extended }
Const F1=#59; Shift_F1=#84; Ctrl_F1=#94; Alt_F1=#104;
F2=#60; Shift_F2=#85; Ctrl_F2=#95; Alt_F2=#105;
F3=#61; Shift_F3=#86; Ctrl_F3=#96; Alt_F3=#106;
F4=#62; Shift_F4=#87; Ctrl_F4=#97; Alt_F4=#107;
F5=#63; Shift_F5=#88; Ctrl_F5=#98; Alt_F5=#108;
F6=#64; Shift_F6=#89; Ctrl_F6=#99; Alt_F6=#109;
F7=#65; Shift_F7=#90; Ctrl_F7=#100; Alt_F7=#110;
F8=#66; Shift_F8=#91; Ctrl_F8=#101; Alt_F8=#111;
F9=#67; Shift_F9=#92; Ctrl_F9=#102; Alt_F9=#112;
F10=#68; Shift_F10=#93; Ctrl_F10=#103; Alt_F10=#113;
F11=#133; Shift_F11=#135; Ctrl_F11=#137; Alt_F11=#139; {****}
F12=#134; Shift_F12=#136; Ctrl_F12=#138; Alt_F12=#140; {****}
Alt_1=#120; Alt_2=#121; Alt_3=#122; Alt_4=#123;
Alt_5=#124; Alt_6=#125; Alt_7=#126; Alt_8=#127;
Alt_9=#128; Alt_0=#129;
Alt_A=#30; Alt_B=#48; Alt_C=#46; Alt_D=#32;
Alt_E=#18; Alt_F=#33; Alt_G=#34; Alt_H=#35;
Alt_I=#23; Alt_J=#36; Alt_K=#37; Alt_L=#38;
Alt_M=#50; Alt_N=#49; Alt_O=#24; Alt_P=#25;
Alt_Q=#16; Alt_R=#19; Alt_S=#31; Alt_T=#20;
Alt_U=#22; Alt_V=#47; Alt_W=#17; Alt_X=#45;
Alt_Y=#21; Alt_Z=#44;
Shift_Tab=#15;
Ctrl_tab=#148; {*}
Alt_tab=#165; {*}
Alt_Esc=#1; {*}
alt_BS=#14; {*}
Home=#71;
Up=#72;
PgUp=#73;
Left=#75;
Right=#77;
End_=#79; { Note the underscore as End is a reserved word }
Down=#80;
PgDn=#81;
Ins=#82;
Del=#83;
Ctrl_PrtSc=#114;
Ctrl_Left=#115;
Ctrl_Right=#116;
Ctrl_End=#117;
Ctrl_PgDn=#118;
Ctrl_Home=#119;
Ctrl_PgUp=#132;
implementation
{$undef asm}
{$ifdef ver70} {$define asm} {$endif}
{$ifdef ver60} {$define asm} {$endif}
{$ifndef asm}
uses dos;
{$endif}
const scancode:char=#0;
{ This routine replaces crt.keypressed. It uses int 16h, ah=11h.
if there is a scancode in buffer then it immediately returns true }
{$ifndef asm}
function keypressed:boolean;
var rg:registers;
begin
if scancode>#0 then keypressed:=true
else begin
rg.ah:=ord(extended_kbd)*$10+1;
intr($16,rg);
keypressed:=rg.flags and fzero=0;
End;
End;
{$else}
function keypressed:boolean; assembler;
asm
cmp scancode,0
jz @peek
mov al,1
ret
@peek: mov ah,extended_kbd
mov cl,4
shl ah,cl
inc ah
int 16h
mov al,1
jnz @out
xor al,al
@out: end;
{$endif}
{ This routine replaces the crt.readkey. It uses int 16h. ah=10h.
If there is a scancode in buffer it is immediately returned.
They grey cursor keys report E0h as ASCII code instead of
zero, so this has to be changed to zero. However, one must be
careful as ASCII E0h (224d) can also be alpha as entered from
keypad }
{$ifndef asm}
function readkey:char;
var rg:registers;
begin
if scancode>#0 then begin
readkey:=scancode;
scancode:=#0;
exit;
End;
rg.ah:=ord(extended_kbd)*$10;
intr($16,rg);
if (rg.al=$E0) and (rg.ah>70) then rg.al:=0; { Grey cursor keys }
readkey:=chr(rg.al);
if rg.al=0 then scancode:=chr(rg.ah);
End;
{$else}
function readkey:char; assembler;
asm
mov al,scancode
or al,al
jz @new
mov scancode,0
ret
@new: mov ah,extended_kbd
mov cl,4
shl ah,cl
int 16h
cmp al,0E0h
jne @x
cmp al,70
jbe @x
xor al,al
@x: or al,al
jnz @out
mov scancode,ah
@out: end;
{$endif}
var tmp:byte;
tmp2:word;
function status:word;
inline(
$B8/$00/$12/ {MOV AX,1200h}
$CD/$16 {INT 16h }
);
{$ifdef msdos}
const seg0040=$40;
{$endif}
begin
tmp:=mem[Seg0040:$17];
extended_kbd:=false;
if lo(status)=tmp then begin
mem[Seg0040:$17]:=tmp xor 7;
tmp2:=status;
extended_kbd:=(tmp2<>$1200) and (lo(tmp2)=tmp xor 7);
mem[Seg0040:$17]:=tmp;
End;
end.
Osmo
Technical Details
Message-ID:
<6tte0m$8i8@kruuna.Helsinki.FI>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6ton52$ip0$1@news3.cableinet.co.uk> <yT_L1.1904$VW6.13569796@news.magma.ca> <3600FFBD.518F@GECM.COM> <Y36aWFAoLVA2Ywpv@pedt.demon.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111659,6641efc813030989 X-Google-Attributes: gid111659,public X-Google-Thread: 108ebd,6641efc813030989 X-Google-Attributes: gid108ebd,public From: ronkanen@cc.helsinki.fi (Osmo Ronkanen) Subject: Re: ASCII Codes... Date: 1998/09/18 Message-ID: <6tte0m$8i8@kruuna.Helsinki.FI> X-Deja-AN: 392373900 References: <6ton52$ip0$1@news3.cableinet.co.uk> <yT_L1.1904$VW6.13569796@news.magma.ca> <3600FFBD.518F@GECM.COM> <Y36aWFAoLVA2Ywpv@pedt.demon.co.uk> Organization: University of Helsinki Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal