home *** CD-ROM | disk | FTP | other *** search
- {skeletal Pascal source to handle the various DOS extended key codes}
- {TITLE: IBM PC Alt/Ctrl/Shift & Function Keys}
-
- program kbdrtns;
- Type
- RegType = record case integer of
- 0:(Ax,Bx,Cx,Dx,Bp,Si,Di,Ds,Es,Flags:integer);
- 1:(Al,Ah,Bl,Bh,Cl,Ch,Dl,Dh:byte);
- 2:(words:array[0..9] of integer);
- 3:(bytes:array[0..7] of byte)
- end;
-
- var c:char;
-
-
- procedure manager(which:byte);
- const LeftArrow='L';RightArrow='R';Home='H';Endd='E';
- UpArrow='u';DownArrow='d';
- PgUp='U';PgDn='D';Ins='+';Del='-';BackTab='B';ForwardTab='F';
- numpad:string[13]='HuU?L?R?EdD+-';
- cnumpad:string[18]='LREDH????????????U';
- toprow:string[12]='1234567890-=';
- qwerty:string[35]='qwertyuiop????asdfghjkl?????zxcvbnm';
- var ch:char;
- begin
- ch:='?';
- case which of
- 16..25,30..38,44..50,120..131:
- begin {Alt keys}
- if which>=120 then ch:=toprow[which-119] else ch:=qwerty[which-15];
- case ch of
- 'a':;
- 'b':;
- 'c':;
- 'd':;
- 'e':;
- 'f':;
- 'g':;
- 'h':;
- 'i':;
- 'j':;
- 'k':;
- 'l':;
- 'm':;
- 'n':;
- 'o':;
- 'p':;
- 'q':;
- 'r':;
- 's':;
- 't':writeln('You just typed Alt-t');
- 'u':;
- 'v':;
- 'x':;
- 'y':;
- 'z':;
- '0':;
- '1':;
- '2':;
- '3':;
- '4':;
- '5':;
- '6':;
- '7':;
- '8':;
- '9':;
- end;
- end;
- 104..113:case which-103 of {alt function keys}
- 1:writeln('You just typed Alt-F1');
- 2:;
- 3:;
- 4:;
- 5:;
- 6:;
- 7:;
- 8:;
- 9:;
- 10:;
- end;
- 59..68:case which-58 of {function keys}
- 1:writeln('You just typed F1');
- 2:;
- 3:;
- 4:;
- 5:;
- 6:;
- 7:;
- 8:;
- 9:;
- 10:;
- end;
- 84..93:case which-83 of {shift function keys}
- 1:writeln('You just typed Shift-F1');
- 2:;
- 3:;
- 4:;
- 5:;
- 6:;
- 7:;
- 8:;
- 9:;
- 10:;
- end;
- 94..103:case which-93 of {ctrl function keys}
- 1:writeln('You just typed Ctrl-F1');
- 2:;
- 3:;
- 4:;
- 5:;
- 6:;
- 7:;
- 8:;
- 9:;
- 10:;
- end;
- 151..157,160..162,164..176:
- case chr(which-54) of {ctrl keys}
- 'a':;
- 'b':;
- {ctrl-c or ctrl-break is not intercepted}
- 'd':;
- 'e':;
- 'f':;
- 'g':;
- {note: ctrl-h is taken to be backspace}
- 'i':;
- 'j':;
- 'k':;
- 'l':;
- {note: ctrl-m is taken to be Enter [CR]}
- 'n':;
- 'o':;
- 'p':;
- 'q':;
- 'r':;
- 's':;
- 't':writeln('You just typed Ctrl-t');
- 'u':;
- 'v':;
- 'x':;
- 'y':;
- 'z':;
- end;
- 15,71..73,75,
- 77,79..83,159:
- begin
- if which=15 then ch:=BackTab else
- if which=159 then ch:=ForwardTab else
- ch:=numpad[which-70];
- case ch of {numeric key pad keys}
- BackTab:writeln('You just typed BackTab');
- ForwardTab:;
- Home:;
- UpArrow:;
- PgUp:;
- LeftArrow:;
- RightArrow:;
- Endd:;
- DownArrow:;
- PgDn:writeln('You just typed PgDn');
- Ins:;
- Del:;
- end;
- end;
- 115..119,132:
- begin
- case cnumpad[which-114] of {ctrl-numeric key pad keys}
- LeftArrow:;
- RightArrow:;
- Endd:writeln('You just typed Ctrl-End');
- PgDn:;
- Home:;
- PgUp:;
- end;
- end;
- end;
- end;
-
- function kbchar:char;
- var r:regtype;
- begin
- r.ah:=$0b;
- msdos(r);
- if r.al = 0 then kbchar:=#0
- else begin
- r.ah:=$07;
- msdos(r);
- if r.al<>0 then
- if r.al in [8,13,27,32..127] then kbchar:=chr(r.al)
- else begin manager(r.al+150);kbchar:=#0 end
- else
- begin
- r.ah:=$07;
- msdos(r);
- manager(r.al);
- kbchar:=#0
- end;
- end;
- end;
-
- begin
- repeat
- c:=kbchar;
- if c<>#0 then writeln(c,' = ',ord(c))
- until c='q';
- writeln('Done!')
- end.
-