1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| TForm1 = class(TForm)
Infos: TStatusBar;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ private declarations }
Appuye: Boolean;
PosD, PosA: TPoint;
public
{ public declarations }
end;
function GetCursorState: TShiftState;
var
Form1: TForm1;
implementation
{$R *.lfm}
function GetCursorState: TShiftState;
begin
Result := [];
if (GetKeyState(VK_LBUTTON) and $8000) <> 0 then
Include(Result, ssLeft);
if (GetKeyState(VK_MBUTTON) and $8000) <> 0 then
Include(Result, ssMiddle);
if (GetKeyState(VK_RBUTTON) and $8000) <> 0 then
Include(Result, ssRight);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
PosC: TPoint;
State: TShiftState;
begin
GetCursorPos(PosC); // retrouve la position de la souris
State:= GetCursorState; // retroue l'état des touche de la souris
if not Appuye and (ssLeft in State) then
begin
Infos.Panels[2].Text:= 'DOWN';
Appuye:= True;
PosD:= PosC;
end
else
if Appuye and not(ssLeft in State) then
begin
Infos.Panels[2].Text:= 'UP';
Appuye:= False;
PosA:= PosC;
if not Application.Active then
begin
Infos.Panels[0].Text:= IntToStr(PosD.x-PosA.x);
Infos.Panels[1].Text:= IntToStr(PosD.y-PosA.y);
end;
end;
end;
end. |