od hosť » 12 Feb 2008, 15:54
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
Tx : Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Tx:=False;
end;
procedure TForm1.Button1Click(Sender: TObject);
var NewPos,OldPos : TPoint;
begin
// Tento príklad simuluje po kliknutí na tlačítko Button1
// kliknutie na tlačítko Button2
Tx:=True;
OldPos:=Mouse.CursorPos;
with Button2 do
NewPos:=Point(Left + Width div 2, Top + Height div 2);
NewPos:=ClientToScreen(NewPos);
Mouse.CursorPos:=NewPos;
NewPos.x:=Round(NewPos.x * (65535/Screen.Width));
NewPos.y:=Round(NewPos.y * (65535/Screen.Height));
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE, NewPos.x,NewPos.y,0,0);
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, NewPos.x,NewPos.y,0,0);
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, NewPos.x,NewPos.y,0,0);
Sleep(2000);
Mouse.CursorPos:=OldPos;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if Tx then
begin
Tx:=False;
Label1.Caption:='Klikol si na Button1 ale ako keby si klikol na Button2 !';
end
else Label1.Caption:='Klikol si na Button2';
Label1.Refresh;
Sleep(2000);
Label1.Caption:='';
end;
end.