Skip to content

Commit b3de4a9

Browse files
committed
IMP: Correct HOME and END key codes. Add support for them to text editor.
Also add support to PromptString (cheat box): pressing HOME clears the whole line.
1 parent 6663d3b commit b3de4a9

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/game.pas

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ procedure PromptString(x, y, arrowColor, color, width: integer; mode: byte; var
579579

580580
InputReadWaitKey;
581581

582-
if (Length(buffer) < width) and (InputKeyPressed >= #32) then begin
582+
if (Length(buffer) < width) and (InputKeyPressed >= #32) and (not InputSpecialKeyPressed) then begin
583583
if firstKeyPress then
584584
buffer := '';
585585
case mode of
@@ -602,6 +602,9 @@ procedure PromptString(x, y, arrowColor, color, width: integer; mode: byte; var
602602
end;
603603
end else if (InputKeyPressed = KEY_LEFT) or (InputKeyPressed = KEY_BACKSPACE) then begin
604604
buffer := Copy(buffer, 1, Length(buffer) - 1);
605+
{IMP: Clear the whole line if Home is pressed.}
606+
end else if (InputKeyPressed = KEY_HOME) then begin
607+
buffer := '';
605608
end;
606609

607610
firstKeyPress := false;

src/input.pas

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ interface
5151
KEY_PAGE_DOWN = #209;
5252
KEY_INSERT = #210;
5353
KEY_DELETE = #211;
54-
KEY_HOME = #212;
55-
KEY_END = #213;
54+
KEY_HOME = #199;
55+
KEY_END = #207;
5656
KEY_SHIFT_UP = #193;
5757
KEY_SHIFT_DOWN = #194;
5858
KEY_SHIFT_LEFT = #196;
@@ -64,6 +64,7 @@ interface
6464
InputShiftAccepted: boolean;
6565
InputJoystickEnabled: boolean;
6666
InputMouseEnabled: boolean;
67+
InputSpecialKeyPressed: boolean;
6768
InputKeyPressed: char;
6869
InputMouseX, InputMouseY: integer;
6970
InputMouseActivationX, InputMouseActivationY: integer;
@@ -107,20 +108,36 @@ procedure InputUpdate;
107108
InputKeyPressed := ReadKey;
108109
utf[0] := Byte(InputKeyPressed);
109110
{ Special keys }
110-
if (InputKeyPressed = #0) or (InputKeyPressed = #1) or (InputKeyPressed = #2) then
111-
InputKeyBuffer := InputKeyBuffer + Chr(Ord(ReadKey) or $80)
111+
if (InputKeyPressed = #0) or (InputKeyPressed = #1) or (InputKeyPressed = #2) then begin
112+
InputKeyBuffer := InputKeyBuffer + Chr(Ord(ReadKey) or $80);
113+
InputSpecialKeyPressed := True;
112114
{ Key corresponding to multi-byte UTF8 }
113-
else if utf[0] > $7F then begin
115+
end else if utf[0] > $7F then begin
114116
i := 1;
115117
while (i <= 3) and ByteBool((utf[0] shl i) and %10000000) do begin
116118
utf[i] := Byte(ReadKey);
117119
inc(i);
118120
end;
119121

120122
InputKeyBuffer := InputKeyBuffer + CodepointToCP437(UTF8ToCodepoint(utf));
121-
122-
end else { Ordinary key }
123+
InputSpecialKeyPressed := False;
124+
end else begin { Ordinary key, or... }
125+
InputSpecialKeyPressed := False;
126+
{ Ugly hack for Linux console and the end key. For
127+
some reason it outputs F[F[. }
128+
if (InputKeyPressed = #70) and KeyPressed then begin
129+
InputKeyPressed := ReadKey;
130+
if InputKeyPressed = '[' then begin
131+
{ Get rid of the second F[. }
132+
if KeyPressed then ReadKey;
133+
if KeyPressed then ReadKey;
134+
135+
InputKeyPressed := KEY_END;
136+
InputSpecialKeyPressed := True;
137+
end else InputKeyPressed := #70;
138+
end;
123139
InputKeyBuffer := InputKeyBuffer + InputKeyPressed;
140+
end;
124141
TCFlush(0, TCIFLUSH); { Flush the keybuffer. }
125142
end;
126143
if Length(InputKeyBuffer) <> 0 then begin
@@ -219,6 +236,7 @@ procedure InputReadWaitKey;
219236
InputDeltaY := 0;
220237
InputShiftPressed := false;
221238
InputShiftAccepted := false;
239+
InputSpecialKeyPressed := false;
222240
InputMouseX := 0;
223241
InputMouseY := 0;
224242
InputMouseActivationX := 60;

src/txtwind.pas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ procedure TextWindowEdit(var state: TTextWindowState);
426426
KEY_DOWN: newLinePos := LinePos + 1;
427427
KEY_PAGE_UP: newLinePos := LinePos - TextWindowHeight + 4;
428428
KEY_PAGE_DOWN: newLinePos := LinePos + TextWindowHeight - 4;
429+
{IMP: END and HOME}
430+
KEY_END: charPos := Length(Lines[LinePos]^) + 1;
431+
KEY_HOME: charPos := 1;
429432
KEY_RIGHT: begin
430433
charPos := charPos + 1;
431434
if charPos > (Length(Lines[LinePos]^) + 1) then begin

0 commit comments

Comments
 (0)