URGENT - Simulate MouseClick on a specific form

Hi again,

How can I programatically sumulate a mouseclick on a specific form please?



ST3VOAsked:
Who is Participating?
 
MerijnBSr. Software EngineerCommented:
you'll have to figure out the right mouse pos yourself (is now 100, 100)

procedure TForm13.Button1Click(Sender: TObject);
var Inputs: array of TInput;
begin
 Mouse.CursorPos := Point(100, 100);

 SetLength(Inputs, 2);

 Inputs[0].Itype := INPUT_MOUSE;
 Inputs[0].mi.dwFlags := MOUSEEVENTF_LEFTDOWN;

 Inputs[1].Itype := INPUT_MOUSE;
 Inputs[1].mi.dwFlags := MOUSEEVENTF_LEFTUP;

 SendInput(2, Inputs[0], SizeOf(TInput));
end;
0
 
MerijnBSr. Software EngineerCommented:
can you please be more specific what you want to achieve?
0
 
ST3VOAuthor Commented:
Well...this is what's happening...

I start my application....

Form1:
It loads stuff into memory and I have a Loading Please Wait ... text on it.

Form2:
This Form is a small ToolBar type aligned on the bottom on top of Form1, which is the main form.

All this is fine BUT....The Please Wait ... stays on the form forever and doesn't go to the next level until I Click My mouse on Form1.

Otherwise it would be working fine.

So, for a quick fix if I can just simulate that MouseClick on Form1 ...it would work fine, unless you know another way!

Hope this explaination helps

Thanks

- ST3VO

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
MerijnBSr. Software EngineerCommented:
I assume you create that please-wait-form yourself.

Do you know why the click on the mainform hides this please-wait-form?
What did you try to make the please-wait-form to go away by itself?
0
 
ST3VOAuthor Commented:
No....The Please Wait Text is on the Main form itself.

It's 3D Programming....and the text is rendered by the engine.

If Form2 doesn't show up it doesn't have a problem BUT when Form2 Shows, then I need to click on Form1 for the rendered Textures to show up.

I think it's a question of focus BUT Form1.Setfocus does not fix it...only me clicking on Form1 does the trick, so that's why I need to do it by code.

Hope this helps further

0
 
diniludCommented:
try

Form1.invalidate
0
 
ST3VOAuthor Commented:
I Get an Access Violation Error when I try to use it :o(

Isn't it better to just simulate to MouseClick on form1???

0
 
diniludCommented:
if don't mind,

    Can you show some code?
0
 
ST3VOAuthor Commented:
I'm still getting an access violation error so I suppose that I need to find where to put the code.

I've create a procedure because I didn't want a Buttonclick...

So this is what i've done:

procedure TForm1.SimMouseClick;
var Inputs: array of TInput;
begin
 Mouse.CursorPos := Point(100, 100);

 SetLength(Inputs, 2);

 Inputs[0].Itype := INPUT_MOUSE;
 Inputs[0].mi.dwFlags := MOUSEEVENTF_LEFTDOWN;

 Inputs[1].Itype := INPUT_MOUSE;
 Inputs[1].mi.dwFlags := MOUSEEVENTF_LEFTUP;

 SendInput(2, Inputs[0], SizeOf(TInput));
end;

Then on the Form2...OnShow...I use:  Form1.SimMouseClick;

But I ge an Access Violation Error

Hmmm



0
 
diniludCommented:
Check your form creation order. Is Form1 is your mainform(first creating form)
0
 
ST3VOAuthor Commented:
Yes it is!

2nd is form2
0
 
MerijnBSr. Software EngineerCommented:
set a breakpoint, try to figure out what causes the AV
0
 
ST3VOAuthor Commented:
OK..I'll give it a shot!!!
0
 
ST3VOAuthor Commented:
The problem seems to be that I need to wait until Form2 is fully loaded until I can call the SimMouseClick procedure.

The question now is .....Got an Idea!!!!!!!!!!!!   I'll get back to you!
0
 
ST3VOAuthor Commented:
GREAT!!!!!

Got it to work!!!! :o)

The Old Good Try...Finally...

procedure TForm2.FormShow(Sender: TObject);
Var f1H, f1w: Integer;
begin
try
blah...blah...blah
finally
Form1.SimMouseClick;
end;

And it works perfectly now!!!

Great!!!

Thanks guys!!!!

- ST3VO
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.