Move the mouse via programming

1

Move mouse to control (example a button) in Delphi with Firemonkey .

I tried this function:

procedure TFuncoes.MouseParaControle(Controle: TControl);
var                // Posiciona o mouse em cima do objeto definido em 
  IrPara: TPoint;  // Ex.: MouseParaControle(button1);
begin
  IrPara.X := Controle.Position.X + (Controle.Size.width div 2); // ERRO
  IrPara.Y := Controle.Position.y + (Controle.size.Height div 2);// ERRO
  if Controle.Parent <> nil then
    begin
      IrPara := Controle.PointInObjectLocal(irPara.x, irPara.Y);       
      //Parent.ClientToScreen(IrPara);
      SetCursorPos(IrPara.X, IrPara.Y);
    end;
end;

ERROR:

  

[dcc32 Error] Trp.Model.Funcoes.pas (214): E2015 Operator not   applicable to this operand type in line

    
asked by anonymous 19.09.2017 / 12:21

1 answer

1

It can be done as follows:

procedure TForm1.BtnClicarClick(Sender: TObject);
begin
  //Chama a função e passa o controller que desejar
  MouseaParaController(BtnAqui);
end;

Procedure TForm1.MouseaParaController(Controle: TControl);
var IrPara: TPoint; // Posiciona o mouse em cima do objeto definido em Ex.: MouseParaControle(button1);
    BarCaptionHeight, BarLeftWidth: Integer;
begin
  //defenir tamanhos das bordas
  BarCaptionHeight := 30; //tamanho aproximado do caption
  BarLeftWidth := 5; //tamanho aproximado do border

  //pegar a posição do componente(botão neste caso)
  IrPara.X := Form1.Left + Controle.Left + BarLeftWidth + (Controle.Width div 2);
  IrPara.Y := Form1.Top + Controle.Top + BarCaptionHeight + (Controle.Height div 2);

  //mandar o mouse para a posição
  if Controle.Parent <> nil then SetCursorPos(IrPara.X, IrPara.Y);
End;

Form1.Left will get the value from the start of the monitor to the form.
Controle.Left will get the value of the end of the border until the component.
BarLeftWidth will get the value of the border.
Controle.Width div 2 will get the start value of the component to the center.

I'll still try to figure out how to not declare variables with the border size of the form.

    
19.09.2017 / 12:38