procedure TForm1.Button1Click(Sender: TObject);
function ScreenToAbsolute(
const P: TPoint): TPoint;
begin
Result.X := P.X * (MAXWORD
div GetSystemMetrics(SM_CXSCREEN));
Result.Y := P.Y * (MAXWORD
div GetSystemMetrics(SM_CYSCREEN));
end;
var
R: TRect;
P: TPoint;
C: TPoint;
begin
GetMenuItemRect(
Handle, Menu.Handle, 0, R);
P.X := (R.Left + R.Right)
div 2;
P.Y := (R.Top + R.Bottom)
div 2;
P := ScreenToAbsolute(P);
GetCursorPos(C);
mouse_event(MOUSEEVENTF_ABSOLUTE
Or MOUSEEVENTF_MOVE, P.X, P.Y, 0, GetMessageExtraInfo);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo);
SetCursorPos(C.X, C.Y);
end;