程序控制鼠标(50分)

  • 主题发起人 主题发起人 wangqinyun
  • 开始时间 开始时间
W

wangqinyun

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样才能让程序控制鼠标移动???
不知道那么大哥能帮小弟的忙啊??
 
示例代码:
procedure TForm1.Button1Click(Sender: TObject);
var
MousePoint: TPoint;
begin
MousePoint.X := Mouse.CursorPos.X + 10;
MousePoint.Y := Mouse.CursorPos.Y + 10;
Mouse.CursorPos := MousePoint;
end;
 
测试 http://xianjun.vicp.net/temp/exe.exe

来自:hfghfghfg, 时间:2003-12-7 14:24:00, ID:2339322 | 编辑
to snb_ywx: 两个多星期。
我没有用hook
procedure MouseMoveTo(x, y: integer);
procedure MouseMoveToWillClick(x, y: integer);
procedure MouseMoveToControl(V: TControl;
WillClick: boolean);

procedure MouseMoveTo(x, y: integer);
var
p: TPoint;
moveX, moveY: integer;
i: integer;
begin

GetCursorPos(p);
while (abs(x - p.X) > 20) or (abs(y - p.y) > 20)do
begin

moveX := (x - p.X);
moveY := (y - p.y);
if abs(moveX) > abs(moveY) then
begin
if moveX > 0 then
i := 20
else
i := -20;
moveY := round(moveY / moveX * i + 0.5);
moveX := i;
end
else
begin
if moveY > 0 then
i := 20
else
i := -20;
moveX := round(moveX / moveY * i + 0.5);
moveY := i;
end;
mouse_event(MOUSEEVENTF_MOVE, moveX, movey, 0, 0);
sleep(50);
GetCursorPos(p);
end;
GetCursorPos(p);
while (p.x <> x) or (p.Y <> y)do
begin
moveX := 0;
moveY := 0;
if x > p.X then
moveX := 1;
if x < p.X then
moveX := -1;
if y > p.y then
movey := 1;
if y < p.y then
movey := -1;
mouse_event(MOUSEEVENTF_MOVE, moveX, movey, 0, 0);
GetCursorPos(p);
end;
end;

procedure MouseMoveToWillClick(x, y: integer);
begin
MouseMoveTo(x, y);
sleep(400);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
end;

procedure MouseMoveToControl(V: TControl;
WillClick: boolean);
var
p: Tpoint;
begin

p.X := v.Width div 2;
p.Y := v.Height div 2;
p := v.ClientToScreen(p);
MouseMoveTo(p.X, p.Y);
if WillClick then
begin
sleep(400);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
end;

end;


proceduredo
_input(v: string);

proceduredo
_Input(v: string);
var
ws: widestring;
i: integer;
str: string;
begin
ws := v;
if screen.ActiveControl <> nil then
begin
for i := 1 to length(ws)do
begin
sleep(100);
str := ws;
Clipboard.SetTextBuf(pchar(str));
SendMessage(screen.ActiveControl.Handle, WM_PASTE, 0, 0);
end;
end;
end;


 
window api:
SetCursorPos
=================
BOOL SetCursorPos(
int X, // horizontal position
int Y // vertical position
);

 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2338257
 
同意 savetime
 
接受答案了.
 
后退
顶部