PDA

View Full Version : شبیه سازی Click موس به صورت ...



mrt_programer
شنبه 04 آذر 1385, 22:17 عصر
در سایت مطالب زیادی دیدم ولی ...

چگونه میتوان کلیک موس را شبیه سازی کرد که برنامه فکر کند کلید موس نگه داشته شده

تشکر :افسرده:

ghabil
شنبه 04 آذر 1385, 22:58 عصر
مثلا دکمه چپ موس روی TestButton :


PostMessage(TestButton.Handle, WM_LBUTTONDOWN, MK_LBUTTON, 0);


فکر کنم احتیاج به توضیح نداره.

m-khorsandi
یک شنبه 05 آذر 1385, 10:00 صبح
احتمالاً میخوای "فرو رفتگی" یه Button رو نشون بدی :

دو تا Button بذار روی فرم،
تو OnClick دکمه 1 بنویس :


var
Mouse_Pos: TPoint;
begin
Mouse_Pos := Point(Button2.Left + 5, Button2.Top + 5);
Mouse_Pos := ClientToScreen(Mouse_Pos);
SetCursorPos(Mouse_Pos.X, Mouse_Pos.Y);
Mouse_Event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
end;

asdfghjkl
یک شنبه 05 آذر 1385, 12:00 عصر
procedure SendLeftButtonClick(X, Y: Integer);
var
ClientX, ClientY: Integer;
Window, Parent: HWnd;
WindowRect: TRECT;

begin
// Set the cursor position to the specified X, Y coordinates.
//
SetCursorPos(X, Y);

// Get the window at that X, Y coordinates.
// (does not get handle to hidden or disabled windows)
//
Window := WindowFromPoint(Point(X, Y));
// Was there a window at that coordinate?
//
if (Window <> 0) then begin
// Get the TRect (top, left, bottom, right coordinates).
//
GetWindowRect(Window, WindowRect);

// And translate the X, Y screen coordinates into the client's
// X, Y coordinates.
//
ClientX := X - WindowRect.Left;
ClientY := Y - WindowRect.Top;

// Get the parent root window.
//
Parent := GetAncestor(Window, GA_ROOT);
if (Parent = 0) then
Parent := Window;

// Check to see if the parent window is already the
// foreground window. If no make it the foreground window.
//
if (Parent <> GetForegroundWindow()) then begin
SetForegroundWindow(Parent);
end;

// Do a left-button click.
//
SendMessage(Window, WM_LBUTTONDOWN, MK_LBUTTON, ClientX or (ClientY shl 16));
SendMessage(Window, WM_LBUTTONUP, 0, ClientX or (ClientY shl 16));
end;
end;

dkhatibi
یک شنبه 05 آذر 1385, 13:38 عصر
دوست عزیز سعی کنید کدها رو تو تگ کد بگذارید به این شکل باید استفاده کنید."
" البته [ را هم بگذارید .
در این صورت کد شما به شکل زیر نمایش داده می شه.
[code]
procedure SendLeftButtonClick(X, Y: Integer);
var
ClientX, ClientY: Integer;
Window, Parent: HWnd;
WindowRect: TRECT;

begin
// Set the cursor position to the specified X, Y coordinates.
//
SetCursorPos(X, Y);

// Get the window at that X, Y coordinates.
// (does not get handle to hidden or disabled windows)
//
Window := WindowFromPoint(Point(X, Y));
// Was there a window at that coordinate?
//
if (Window <> 0) then begin
// Get the TRect (top, left, bottom, right coordinates).
//
GetWindowRect(Window, WindowRect);

// And translate the X, Y screen coordinates into the client's
// X, Y coordinates.
//
ClientX := X - WindowRect.Left;
ClientY := Y - WindowRect.Top;

// Get the parent root window.
//
Parent := GetAncestor(Window, GA_ROOT);
if (Parent = 0) then
Parent := Window;

// Check to see if the parent window is already the
// foreground window. If no make it the foreground window.
//
if (Parent <> GetForegroundWindow()) then begin
SetForegroundWindow(Parent);
end;

// Do a left-button click.
//
SendMessage(Window, WM_LBUTTONDOWN, MK_LBUTTON, ClientX or (ClientY shl 16));
SendMessage(Window, WM_LBUTTONUP, 0, ClientX or (ClientY shl 16));
end;
end;