Move the mouse via programming

Asked

Viewed 680 times

1

Move mouse to control (example a button) on 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 on the line

  • If I was able to help with my answer, you can accept the answer by clicking on the left side of it. If you need any more help let me know.

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 take the value from the beginning of the monitor to the form.
Controle.Left will take the value from the end of the border to the component.
BarLeftWidth will take the value of the border.
Controle.Width div 2 will take the start value of the component to the center.

I will also try to find a way not to declare variables with the border size of the form.

  • In VCL it works but FMX does not.

  • @Jairsilveira I have no recent version with Firemonkey, but I’ll do some research and see if I can help more, is giving some error in specific?

  • @Jairsilveira, see this: https://stackoverflow.com/questions/18224549/mouse-coordinates-to-caret-position-in-firemonkey-tmemo-component

  • @Tmc, change the variable IrPara of TPoint for Trect, this way you can access the positions top, bottom, left, rightof the compound ;D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.