WharWho!!
I got it how I wanted it. A simple self contained solution that does require lots of other units.
Since its just a terminal app, it does not need event loops or buffering or stuff.
Thanks for the suggestion of just using ansii thingies.
I'm now a little bit more knowledgable about xterm things.
Just in case any one is interested:
UNIT MyMouse;
interface
procedure InitMyMouse;
function MyMouseButtons : Boolean;
function MyMouseX : Byte;
function MyMouseY : Byte;
procedure ReadMyMouse;
procedure ClearMyMouse;
implementation
uses
BaseUnix, Termio;
Type
Stype = String[16]; {-- should be plenty }
var
MM : Record
x, y : Byte;
b : Boolean;
end;
procedure InitMyMouse;
var
Tio : Termios;
begin
{-- set console to raw mode }
TcGetAttr(1, Tio);
SetTextLineEnding(OutPut, #13#10);
CFMakeRaw(Tio);
TcSetAttr(1, TCSANOW, Tio);
write(#27'[?1036s'#27'[?1036h'); {-- tell keyboard to send escape sequences }
write(#27'[?1006h'); { try to enable Extended/SGH 1006 mouse tracking }
Write(#27'[?9h'); {-- x10 mouse mode.....only reports when a mouse button is pressed }
end;
function MyMouseButtons : Boolean;
begin
MyMouseButtons := MM.b;
end;
function MyMouseX : Byte;
begin
MyMouseX := MM.X;
end;
function MyMouseY : Byte;
begin
MyMouseY := MM.Y;
end;
procedure ClearMyMouse;
begin
MM.x := 0;
MM.y := 0;
MM.b := False;
end;
function KeyPressed : Boolean;
var
fdsin : tfdSet;
begin
fpFD_ZERO(fdsin);
fpFD_SET(StdInputHandle, fdsin);
Keypressed := (fpSelect(StdInputHandle+1, @fdsin, nil, nil, 0) > 0);
end;
function StrToInt(S : Stype) : Byte;
begin
case Length(s) of
1 : StrToInt := Ord(S[1]) - 48;
2 : StrToInt := 10*(Ord(S[1]) - 48) + (Ord(S[2]) - 48);
else
StrToInt := 0;
end;
end;
procedure ReadMyMouse;
{-- waits for a button press and then returns mouse info }
var
S : Stype;
ChStr : String[2];
x : byte;
NumRead : LongInt;
begin
S := '';
repeat
ClearMyMouse;
if KeyPressed then {-- waits for a key event, which include mouse events }
begin
repeat
NumRead := fpRead(StdInputHandle, S, 16);
until Numread <> -1;
{-- pull apart the ansi string returned by the terminal }
{-- get button press info }
Delete(S, 1, 2);
MM.b := s[1] = '0';
Delete(s, 1, 2);
{-- get X coord }
x := Pos(';', s)-1;
ChStr := Copy(s, 1, x);
MM.X := StrToInt(ChStr);
Delete(s, 1, x + 1);
{-- get Y coord }
x := Pos('M', s) -1;
ChStr := Copy(s, 1, x);
MM.Y := StrToInt(ChStr);
end;
until MM.b;
end;
begin
end.