Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-21-2001, 03:16 AM
digitiger digitiger is offline
Senior Member
 
Join Date: Jan 2001
Posts: 716
Default moving mouse cursor & clicking it programmatically

i want to move the mouse cursor to specific positions depending on certain system conditions and also want to click its left button through my mouse without any user intervention. is there any way for that
Reply With Quote
  #2  
Old 01-21-2001, 04:46 AM
OregonGhost OregonGhost is offline
Member
 
Join Date: Jan 2001
Posts: 77
Default RE: moving mouse cursor & clicking it programmatically

you can set the cursor position with
SetCursorPos(p: TPoint);
as you can get it with
GetCursorPos(p: TPoint);

Now click with this code:
SendMessage(WindowFromPoint(p), WM_LBUTTONDOWN, MAKELPARAM(p.x, p.y), 0);
I did not test it but it should work.
Oregon Ghost
Reply With Quote
  #3  
Old 01-21-2001, 05:51 AM
AlexBelgium AlexBelgium is offline
Member
 
Join Date: Jan 2001
Posts: 30
Default RE: moving mouse cursor & clicking it programmatically

mouseX,mouseY are the coords of the pixel you wanna click on
ResetMouse = True if you want the mouse to return to its previous position after clicking
Relative = True if you want the coords be relative to the active window


procedure LeftClick(mouseX,mouseY:Word;ResetMouse:Boolean=Fa lse;Relative:Boolean=True);
var p:TPoint;
win:HWND;
wRect:TRect;
begin
GetCursorPos(p);
if Relative then begin
win:=GetForegroundWindow;
GetWindowRect(win,wRect);
mouseX:=mouseX+wRect.Left;
mouseY:=mouseY+wRect.Top;
end;
SetCursorPos(mouseX,mouseY);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
if ResetMouse then SetCursorPos(p.x,p.y);
end;

procedure RightClick(mouseX,mouseY:Word;ResetMouse:Boolean=F alse;Relative:Boolean=True);
var p:TPoint;
win:HWND;
wRect:TRect;
begin
GetCursorPos(p);
if Relative then begin
win:=GetForegroundWindow;
GetWindowRect(win,wRect);
mouseX:=mouseX+wRect.Left;
mouseY:=mouseY+wRect.Top;
end;
SetCursorPos(mouseX,mouseY);
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
if ResetMouse then SetCursorPos(p.x,p.y);
end;
Reply With Quote
  #4  
Old 01-21-2001, 06:03 AM
Lapince Lapince is offline
Senior Member
 
Join Date: Jan 2001
Posts: 163
Default RE: RE: moving mouse cursor & clicking it programmatically

You can replace
SetCursorPos(mouseX,mouseY);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

by
mouse_event(MOUSEEVENTF_LEFTDOWN or MOUSEEVENTF_MOVE, mouseX, mouseY, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP or MOUSE_MOVE, mouseX, mouseY, 0, 0);
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:41 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.