Recent

Author Topic: simulating a mouse click  (Read 16729 times)

slinger

  • New Member
  • *
  • Posts: 19
simulating a mouse click
« on: March 10, 2012, 09:27:33 am »
I know someone who wants a program that does this, I've done a little research but found nothing. Does anyone know how t do this? Thanks in advanced :)
edit: I forgot, I also need to know how to position the mouse.
edit2: I need to click a button on a flash program.
« Last Edit: March 10, 2012, 01:31:56 pm by slinger »
~slinger

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: simulating a mouse click
« Reply #1 on: March 10, 2012, 10:00:14 am »
The question is how to simulate a mouse click, right?
Easy, just call the control's OnClick event from your code.
For real mouse clicks you get the position in X and Y params of OnMouseDown event.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

slinger

  • New Member
  • *
  • Posts: 19
Re: simulating a mouse click
« Reply #2 on: March 10, 2012, 10:46:34 am »
That totally makes sense! Thanks!
one question left to be answered, how to set the x/y of the mouse :)
edit: blarg, after looking at the code you gave me I'm sure it does this ^
I'm having trouble calling the OnMouseDown event ;-;
« Last Edit: March 10, 2012, 11:08:43 am by slinger »
~slinger

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: simulating a mouse click
« Reply #3 on: March 10, 2012, 11:21:51 am »
Ah, you want to change the mouse position, not get the existing position.
I don't know how to do it.
Usually it is not a good idea, you will only irritate your users with a jumping mouse cursor.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

slinger

  • New Member
  • *
  • Posts: 19
Re: simulating a mouse click
« Reply #4 on: March 10, 2012, 12:06:10 pm »
Haha, yeah it might irritate my users but I have no other idea how to make the mouse click on a selected x/y position. I'm still fairly new to lazarus and pascal.
~slinger

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: simulating a mouse click
« Reply #5 on: March 10, 2012, 12:34:36 pm »
Haha, yeah it might irritate my users but I have no other idea how to make the mouse click on a selected x/y position. I'm still fairly new to lazarus and pascal.

This is not related to pascal or lazarus, it sounds more like an issue of bad design.
How do you select the x/y position if not by mouse?

To answer your question about how to make the mouse click on a selected position:
  The right way is to move the mouse with your hand and then click its button with your index finger.  Yes  :)

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

slinger

  • New Member
  • *
  • Posts: 19
Re: simulating a mouse click
« Reply #6 on: March 10, 2012, 12:40:27 pm »
Yeah, the guy wants to play a game that normally doesn't have an AI but he wants me to design an "auto clicker"(first time i've ever heard of one lol) that moves the mouse to the x/y of a button and clicks. I totally agree with you though use the mouse pad xD
~slinger

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: simulating a mouse click
« Reply #7 on: March 10, 2012, 12:55:44 pm »
Yeah, the guy wants to play a game that normally doesn't have an AI but he wants me to design an "auto clicker"(first time i've ever heard of one lol) that moves the mouse to the x/y of a button and clicks. I totally agree with you though use the mouse pad xD

The click action can be simulated easily by calling the button's OnClick event handler.
I guess you need an animated cursor movement to indicate that an certain button gets pressed. It would move linearly with constant speed and stop on the button.
I would use an image animation drawn on the game canvas, faking the cursor. The real cursor could be hidden for that time.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

slinger

  • New Member
  • *
  • Posts: 19
Re: simulating a mouse click
« Reply #8 on: March 10, 2012, 12:58:21 pm »
Hey that's a great idea! I'll try to figure that out lol.
edit: can I have some code for calling the OnClick procedure?
« Last Edit: March 10, 2012, 01:01:37 pm by slinger »
~slinger

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: simulating a mouse click
« Reply #9 on: March 10, 2012, 01:12:17 pm »
edit: can I have some code for calling the OnClick procedure?

The handler is a normal method, you can call it like any method. Pass the button as the Sender param if the method uses it.
You can also call the handler indirectly through the event:

  Button1.OnClick(Button1);

or something.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

slinger

  • New Member
  • *
  • Posts: 19
Re: simulating a mouse click
« Reply #10 on: March 10, 2012, 01:24:20 pm »
Ok, thanks for all your help, I appreciate it ^^
I'm thinking this only works with a button in the program you are running right? I'm trying to click say the post button on this site. This program that he wants to use the clicker is made in flash I believe...
~slinger

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: simulating a mouse click
« Reply #11 on: March 10, 2012, 01:29:29 pm »
Ok, thanks for all your help, I appreciate it ^^
I'm thinking this only works with a button in the program you are running right? I'm trying to click say the post button on this site. This program that he wants to use the clicker is made in flash I believe...

Uhhh...
You could have mentioned this is about web-programming. It is a whole different topic. I can't help you there.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: simulating a mouse click
« Reply #12 on: March 10, 2012, 02:24:13 pm »
Yeah, the guy wants to play a game that normally doesn't have an AI but he wants me to design an "auto clicker"(first time i've ever heard of one lol) that moves the mouse to the x/y of a button and clicks. I totally agree with you though use the mouse pad xD
I used to make a bot to Diablo 2 that automated some things in singleplayer game  :P  Basically, for this problem you can propably straight use WinAPI, or were you using Linux?

There is something about simulating click:
http://www.cplusplus.com/forum/windows/24162/

Also do a google search about the topic, keywords being "winapi simulate mouse click". Here it doesn't matter what programming language the code is written, you have same functions with freepascal.

As for mouse movement, also from Windows unit commands GetCursorPos and SetCursorPos.

Or there is some written in Delphi:
http://delphi.about.com/od/vclusing/a/mouseadvanced.htm
« Last Edit: March 10, 2012, 02:29:05 pm by User137 »

slinger

  • New Member
  • *
  • Posts: 19
Re: simulating a mouse click
« Reply #13 on: March 11, 2012, 12:43:46 pm »
Thanks! That's exactly what I needed ^^
(am I required to close the topic?)
~slinger

 

TinyPortal © 2005-2018