Recent

Author Topic: Simulate Mouseclick  (Read 12204 times)

gorrila

  • Newbie
  • Posts: 2
Simulate Mouseclick
« on: January 12, 2010, 01:30:34 pm »
Hi there,

I searched the whole forum, tried the examples but I didn't find a solution.
I am trying to simulate a mouseclick with Lazarus, I wrote the same program in Delphi7 and there's an easy command for that.
Code: [Select]
SetCursorPos(x, y);
//Delphi
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

Does anybody know a way?

gorrila

  • Newbie
  • Posts: 2
Re: Simulate Mouseclick
« Reply #1 on: January 12, 2010, 02:36:19 pm »
Solved the problem.

DougNettleton

  • Jr. Member
  • **
  • Posts: 84
Re: Simulate Mouseclick
« Reply #2 on: January 12, 2010, 09:02:47 pm »
Sharing the solution would be a lot better.  Otherwise, the next person that ...

"... searched the whole forum, tried the examples but didn't find a solution."

will find this thread but still not the solution.

TIA,

Doug

tango13

  • New Member
  • *
  • Posts: 36
Re: Simulate Mouseclick
« Reply #3 on: March 13, 2010, 09:53:21 am »
Exactly what happened to me...
Just saying "problem solved" is of no big use in a community forum.
I'll see what I can find and eventually post my solution.
« Last Edit: March 13, 2010, 09:57:02 am by tango13 »

tango13

  • New Member
  • *
  • Posts: 36
Re: Simulate Mouseclick
« Reply #4 on: March 14, 2010, 08:38:59 pm »
Well, don't know whether there are better or more elegant solutions, but one that works for me is using the mouseandkeyinput component found in the "components" folder of the lazarus source tree.

Ciao,
Piero

cjote

  • Newbie
  • Posts: 1
Re: Simulate Mouseclick
« Reply #5 on: October 02, 2013, 10:27:44 pm »
>:D ... Hi,  I want to say the solution and it is the same   8-)

*************
var
  lPto : TPoint;
  lMou : TMouse;

begin

  lPto.x := 50;
  lPto.y := 50;
  lMou.CursorPos := lPto;

  {Simulate the left mouse button down}
   Mouse_Event(MOUSEEVENTF_ABSOLUTE or
               MOUSEEVENTF_LEFTDOWN,
               lPto.x, lPto.y, 0, 0) ;

  {Simulate the left mouse button up}
   Mouse_Event(MOUSEEVENTF_ABSOLUTE or
               MOUSEEVENTF_LEFTUP,
               lPto.x, lPto.y, 0, 0) ;

*************

Regards,
cjote

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Simulate Mouseclick
« Reply #6 on: October 04, 2013, 03:54:27 pm »
Mouse_Event() may not be crossplatform solution, but TMouseInput is.

Open "Project Inspector" dialog, and add lazmouseandkeyinput. Then add mouseandkeyinput in your unit's uses-list. You can then use for example
Code: [Select]
MouseInput.Down(mbLeft, []);
or
MouseInput.Click(mbLeft, []);
to simulate a down event. See rest of the available commands and stuff in those units.

 

TinyPortal © 2005-2018