unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Buttons;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    cas: TTimer;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    promitac: TTimer;
    Button3: TButton;
    Button4: TButton;
    BitBtn1: TBitBtn;
    Label2: TLabel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Button5: TButton;
    procedure casTimer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure promitacTimer(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  jop,jol:boolean;
  krok:integer;
implementation

uses Unit2;

{$R *.DFM}

function pozice:string;
var t:tpoint;
begin
getcursorpos(t);
pozice:=inttostr(t.x)+','+inttostr(t.y);
end;

function getpozice(smer:char;pozice:string):integer;
var onklik:string;
    dwExtraInfo,dwData: Cardinal;
begin
if pos('klik',pozice)<>0 then begin
onklik:=pozice;
delete(pozice,pos('klik',pozice)-1,length(pozice));
if pos('r',onklik)<>0 then begin
mouse_event(MOUSEEVENTF_RIGHTDOWN,getpozice('x',pozice),getpozice('y',pozice),dwData,dwExtraInfo);
mouse_event(MOUSEEVENTF_RIGHTUP,getpozice('x',pozice),getpozice('y',pozice),dwData,dwExtraInfo);
end else begin
mouse_event(MOUSEEVENTF_LEFTDOWN,getpozice('x',pozice),getpozice('y',pozice),dwData,dwExtraInfo);
mouse_event(MOUSEEVENTF_LEFTUP,getpozice('x',pozice),getpozice('y',pozice),dwData,dwExtraInfo);
end;
end else
case smer of
'x':getpozice:=strtoint(copy(pozice,0,pos(',',pozice)-1));
'y':getpozice:=strtoint(copy(pozice,pos(',',pozice)+1,length(pozice)));
end;
end;

procedure TForm1.casTimer(Sender: TObject);
begin

if (GetAsyncKeyState(1)<>0)and(jol=false)
then begin
listbox1.Items.add(pozice+'lklik');
jol:=true;
end else
if not(GetAsyncKeyState(1)<>0) then
jol:=false;

if (GetAsyncKeyState(2)<>0)and(jop=false)
then begin
listbox1.Items.add(pozice+'rklik');
jop:=true;
end else
if not(GetAsyncKeyState(2)<>0) then
jop:=false;

listbox1.items.add(pozice);

if (GetAsyncKeyState(ord('K'))<>0) then button2.click;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
jol:=false;
jop:=false;
krok:=0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
cas.enabled:=true;
button1.enabled:=false;
button2.enabled:=true;
button3.enabled:=false;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
cas.enabled:=false;
button2.enabled:=false;
button1.enabled:=true;
button3.enabled:=true;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
promitac.enabled:=true;
button3.enabled:=false;
button4.enabled:=true;
if checkbox1.checked then form1.hide;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
promitac.enabled:=false;
krok:=0;
button4.enabled:=false;
button3.enabled:=true;
end;

procedure TForm1.promitacTimer(Sender: TObject);
var pozice:string;
begin
pozice:=listbox1.items[krok];
setcursorpos(getpozice('x',pozice),getpozice('y',pozice));
inc(krok);
if (listbox1.items.count-1)=krok then
if checkbox2.checked then
krok:=0
else begin
promitac.enabled:=false;
krok:=0;
form1.show;
button3.enabled:=true;
button4.enabled:=false;
end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
form2.showmodal;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
listbox1.Clear;
button3.enabled:=false;
end;

end.
