home *** CD-ROM | disk | FTP | other *** search
-
- { File: FUNKEY.INC }
- { Written by: Stew Stryker for CP/M 09/08/84
-
- Converted to MS-DOS 01/30/85 }
- { The only changes made were in the interrupt number, from 40 to 24. }
-
- { Declared set of function key codes for array pointers, instead of
- looping until the codes matched, for improved speed.
- - 4/17/85 - Stew Stryker }
-
-
- Const
- CharEntered = 255;
-
- TYPE
-
- FunKeyCode = ( HELP, KDO, COMPOSE, PRINT, DUM4, F4, DUM6,
- INTERRUPT, DUM8, RESUME, DUM10, CANCEL, DUM12,
- MAIN, DUM14, KEXIT, DUM16, OPTIONS, DUM18, F17,
- DUM20, F18, DUM22, F19, DUM24, F20, DUM26, FIND,
- DUM28, INSERT, DUM30, REMOVE, DUM32, SELECT, DUM34,
- PREV, DUM36, NEXT, DUM38, UP, DUM40, DOWN, DUM42,
- RIGHT, DUM44, LEFT, DUM46, KEY0, DUM48, DUM49,
- KEY1, DUM51, DUM52, KEY2, DUM54, DUM55, KEY3,
- DUM57, DUM58, KEY4, DUM60, DUM61, KEY5, DUM63,
- DUM64, KEY6, DUM66, DUM67, KEY7, DUM69, DUM70,
- KEY8, DUM72, DUM73, KEY9, DUM75, DUM76, KEYMINUS,
- DUM78, DUM79, KEYCOMMA, DUM81, DUM82, KEYPERIOD,
- DUM84, DUM85, KEYENTER, DUM87, DUM88, PF1, DUM90,
- DUM91, PF2, DUM93, DUM94, PF3, DUM96, DUM97,
- PF4, DUM99, DUM100, BREAK);
-
-
- VAR
- InChar : Char;
- InString : STR80;
- FunKeys : ARRAY[FunKeyCode] OF STR80;
- FunShiftCode : Integer;
- FunCode : FunKeyCode;
-
-
- FUNCTION Level2Key(Var InString : Char) : Boolean;
- { This uses level 2 console in calls to get input characters }
- { You should NOT mix Level 2 inputs with the above ReadKey }
- { inputs, as you'll screw up the level 2 key buffer. }
- { This routine is only included to clear the level 2 keyboard }
- { buffer. }
-
- BEGIN
- InString := ^@;
- __SaveRegisters := __Registers;
- { Check if a character has been entered from the keyboard }
- __Registers.CX := 0;
- __Registers.DI := 2;
- Intr(24,__Registers);
-
- { If a char has been entered, decode it }
- If __Registers.CL = CharEntered Then
- Begin
- { A character has been entered }
- Level2Key := True;
- InString := CHR(__Registers.AL);
- END { If a key was pressed }
- Else Level2Key := False; { A key wasn't pressed }
-
- __Registers := __SaveRegisters;
- END; { Function Level2Key }
-
-
- FUNCTION ReadKey : Boolean;
-
- Var
- TempChar : Char;
-
- BEGIN
- InString := ''; { If a char available, it's put in here }
- FunCode := DUM4; { Set dummy value, is checked on return }
- { Check if a character has been entered from the keyboard }
- __SaveRegisters := __Registers;
- __Registers.CX := 0;
- __Registers.DI := 6;
- Intr(24,__Registers);
-
- { If a char has been entered, decode it and print it }
- IF __Registers.CL = CharEntered
- Then Begin
- { A character has been entered }
- ReadKey := True;
- FunShiftCode := __Registers.AH; { Save Shift status }
-
- { Check if they entered a function key }
- IF (__Registers.AH And 1) = 1 { i.e. the value is odd }
- Then
- Begin
- { A function key was pressed }
- FunCode := FunKeyCode(__Registers.AL);
- InString := FunKeys[FunCode];
- End { If this was a function key }
- Else
- { A non-function key was entered, save it. }
- InString := CHR(__Registers.AL);
- End { If a key was pressed }
- Else If __Registers.CL = 1
- Then Begin { A character was received in the Level 2 buffer }
- ReadKey := True;
- While Level2Key(InChar) Do
- InString := Instring + InChar;
- End
- Else ReadKey := False;
-
-
- __Registers := __SaveRegisters;
- END; { Function ReadKey }
-
-
- Procedure ClearLevel2Buffer;
- { To clear the level 2 keyboard input buffer, we'll read }
- { the level 2 buffer until it's empty; or until we've read }
- { a ridulously large number of characters. }
-
- Var
- Counter : Integer;
-
- Begin
- Counter := 0;
- While (Level2Key(InChar)) And (Counter < 255) Do;
- End; { Procedure ClearLevel2Buffer }
-
-
- Procedure NumericKeypadMode;
- { Define numeric keypad with numeric keypad strings }
- Begin
- FunKeys[KEY0] := '0'; { KEY0 }
- FunKeys[KEY1] := '1'; { KEY1 }
- FunKeys[KEY2] := '2'; { KEY2 }
- FunKeys[KEY3] := '3'; { KEY3 }
- FunKeys[KEY4] := '4'; { KEY4 }
- FunKeys[KEY5] := '5'; { KEY5 }
- FunKeys[KEY6] := '6'; { KEY6 }
- FunKeys[KEY7] := '7'; { KEY7 }
- FunKeys[KEY8] := '8'; { KEY8 }
- FunKeys[KEY9] := '9'; { KEY9 }
- FunKeys[KEYMINUS] := '-'; { KEY- }
- FunKeys[KEYCOMMA] := ','; { KEY, }
- FunKeys[KEYPERIOD] := '.'; { KEY. }
- FunKeys[KEYENTER] := ^M; { KEYENTER }
- End; { NumericKeypadMode }
-
-
- Procedure ApplicationKeypadMode;
- { Define numeric keypad with VT100 application keypad strings }
- Begin
- FunKeys[KEY0] := ^[+'Op'; { KEY0 }
- FunKeys[KEY1] := ^[+'Oq'; { KEY1 }
- FunKeys[KEY2] := ^[+'Or'; { KEY2 }
- FunKeys[KEY3] := ^[+'Os'; { KEY3 }
- FunKeys[KEY4] := ^[+'Ot'; { KEY4 }
- FunKeys[KEY5] := ^[+'Ou'; { KEY5 }
- FunKeys[KEY6] := ^[+'Ov'; { KEY6 }
- FunKeys[KEY7] := ^[+'Ow'; { KEY7 }
- FunKeys[KEY8] := ^[+'Ox'; { KEY8 }
- FunKeys[KEY9] := ^[+'Oy'; { KEY9 }
- FunKeys[KEYMINUS] := ^[+'Om'; { KEY- }
- FunKeys[KEYCOMMA] := ^[+'Ol'; { KEY, }
- FunKeys[KEYPERIOD] := ^[+'On'; { KEY. }
- FunKeys[KEYENTER] := ^[+'OM'; { KEYENTER }
- End; { ApplicationKeypadMode }
-
-
- Function GetInitFunkey(Code : FunKeyCode) : STR80;
- Begin
- Case Code Of
- HELP: GetInitFunkey := ^[+'[28~'; { HELP }
- KDO: GetInitFunkey := ^[+'[29~'; { DO }
- COMPOSE: GetInitFunkey := ^[+'[10~'; { COMPOSE }
- PRINT: GetInitFunkey := ''; { PRINT }
- F4: GetInitFunkey := ^[+'[14~'; { F4 }
- INTERRUPT: GetInitFunkey := ^[+'[17~'; { INTERRUPT }
- RESUME: GetInitFunkey := ^[+'[18~'; { RESUME }
- CANCEL: GetInitFunkey := ^[+'[19~'; { CANCEL }
- MAIN: GetInitFunkey := ^[+'[20~'; { MAIN }
- KEXIT: GetInitFunkey := ^[+'[21~'; { EXIT }
- OPTIONS: GetInitFunkey := ^[+'[26~'; { OPTIONS }
- F17: GetInitFunkey := ^[+'[31~'; { F17 }
- F18: GetInitFunkey := ^[+'[32~'; { F18 }
- F19: GetInitFunkey := ^[+'[33~'; { F19 }
- F20: GetInitFunkey := ^[+'[34~'; { F20 }
- FIND: GetInitFunkey := ^[+'[1~'; { FIND }
- INSERT: GetInitFunkey := ^[+'[2~'; { INSERT }
- REMOVE: GetInitFunkey := ^[+'[3~'; { REMOVE }
- SELECT: GetInitFunkey := ^[+'[4~'; { SELECT }
- PREV: GetInitFunkey := ^[+'[5~'; { PREV }
- NEXT: GetInitFunkey := ^[+'[6~'; { NEXT }
- UP: GetInitFunkey := ^[+'[A'; { UP }
- DOWN: GetInitFunkey := ^[+'[B'; { DOWN }
- RIGHT: GetInitFunkey := ^[+'[C'; { RIGHT }
- LEFT: GetInitFunkey := ^[+'[D'; { LEFT }
- PF1: GetInitFunkey := ^[+'OP'; { PF1 }
- PF2: GetInitFunkey := ^[+'OQ'; { PF2 }
- PF3: GetInitFunkey := ^[+'OR'; { PF3 }
- PF4: GetInitFunkey := ^[+'OS'; { PF4 }
- BREAK: GetInitFunkey := ''; { BREAK }
- Else Begin End;
- End; { Case Statement }
- End; { Function GetInitFunkey }
-
-
- PROCEDURE InitFunkeys;
- Var
- CodeCount : FunKeyCode;
- BEGIN
- { Define values of function keys }
-
- For CodeCount := HELP To BREAK Do
- FunKeys[CodeCount] := GetInitFunkey(CodeCount);
-
- NumericKeypadMode; { Initially define keypad as numeric }
- ClearLevel2Buffer; { In preparation for Level 1 inputs }
- { Thank God the definitions are done. }
- END; { Procedure InitFunkeys }
-
-