Mouse Click without moving the Screen Cursor

1

I am doing a simple system, in this FORM has 2 button, one that executes the function and another that I put a SHOWMESSAGE('teste ok'); and I got the POSITION of that second BUTTON, remembering that I need to use SENDMESSAGE for the CURSOR of the MOUSE move on the screen, then did the following program:

Procedure SendMouseClick(x,y:Integer);
var
h:THandle;
begin
h := FindWindow(nil, 'TForm1');
SendMessage(h, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x,y));
sleep(10);
SendMessage(h, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(x,y));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SendMouseClick(1042,538);
end;

It turns out that I click and simply do nothing in my FORM. What can I be wrong?

    
asked by anonymous 12.04.2014 / 22:28

3 answers

3

Maybe I misunderstood, but from what I understand you just want to trigger the click function of the 2nd button. If this is it, just call the function directly. Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Button2Click(Sender);  // pode ser chamada em qualquer lugar, em uma outra função, em um timer, em um evento OnClick do form...
  // Se for o caso em algumas funções não terás o Sender, basta substituir por qualquer outro objeto. Sender identifica que objeto está "disparando" o click.
end;
    
19.09.2014 / 00:14
1

Try using Mouse_Event

{Move mouse}

Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE, COORDENADA X, COORDENADA Y, 0, 0);

{Simulates mouse-click button}

Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, COORDENADA X, COORDENADA Y, 0, 0);

{Simulate by releasing the left mouse button}

Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, COORDENADA X, COORDENADA Y, 0, 0);

Fote: link

    
12.04.2014 / 23:32
1

In event OnClick of Button1 put the following code:

SendMessage(Button2.Handle, WM_LBUTTONDOWN, MK_LBUTTON, 0); 
SendMessage(Button2.Handle, WM_LBUTTONUP, MK_LBUTTON, 0); 

This will mean that when you click on Button1 the message will be sent to WM_LBUTTONDOWN " to the handle of Button2 . The message WM_LBUTTONDOWN is used when press the left mouse button, the

13.04.2014 / 02:30