library mouseevents;

uses
  Windows,
  SysUtils,
  Classes;

{$R *.res}

var MySetPos: PChar;

function numtok(List: String; Delimiter: String): Integer;
begin

Result := 1;
while (Pos(Delimiter, List) > 0) do begin
Delete(List, 1, Pos(Delimiter, List)+Length(Delimiter)-1);
Result:=Result+1;

end;

end;

function gettok(List: String; Position: Integer;
Delimiter: String): String;
var
i, NP: integer;
begin

NP:=0;
if (Position > numtok(List,Delimiter)) then
result:=''
else begin
for i:=1 to Position do begin
List:=Copy(List,NP,Length(List)-NP+1);
NP:=Pos(Delimiter,List)+Length(Delimiter);
if (i = Position) then begin
if (Pos(Delimiter, List) = 0) then break;
Delete(List, NP-Length(Delimiter), Length(List)-(NP-Length(Delimiter)-1));

end;

end;

result:=List;

end;

end;

function movemouse(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

MySetPos:= data;
SetCursorPos(StrToInt(gettok(data,1,#32)),StrToInt(gettok(data,2,#32)));
Result := 1;

end;

function clicklmouse(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);

Result:= 1;
end;

function clickrmouse(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);

Result:= 1;
end;

function hidemouse(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

ShowCursor(False);
Result:= 1;

end;

function showmouse(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

ShowCursor(True);
Result:= 1;

end;

function dlclick(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Result:= 1;

end;

function drclick(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
Result:= 1;

end;

function dragl(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

MySetPos:= data;
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
SetCursorPos(StrToInt(gettok(data,1,#32)),StrToInt(gettok(data,2,#32)));
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Result:= 1;

end;

function dragr(mWnd, aWnd: HWND; data, parms: PChar; show, nopause:boolean):integer; stdcall;
begin

MySetPos:= data;
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
SetCursorPos(StrToInt(gettok(data,1,#32)),StrToInt(gettok(data,2,#32)));
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
Result:= 1;

end;

exports
movemouse, clicklmouse, clickrmouse, hidemouse, showmouse, dlclick, drclick, dragl, dragr;

end.


