Generate clicks for winform app

I have a winform app (C# 4.0). i'm testing a race condition and need to click repeatedly very fast on a form panel, faster than I can click on my mouse. Is there a way to do this?

This click utility should be external to the program itself, since I'll need to run it on the current production version as well as the corrected development version. If the solution involves writing a separate program, would prefer C#.
LVL 1
BlearyEyeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Have you heard of AutoIT? I just tested it out for your specific scenario. It would be one less thing you have to write (well, you'd only have to write a quick script for the clicking).

To simulate your example, I wrote the following in AutoIT's editor:

For $i = 0 To 10000
  ControlClick("Form1", "", "[ID:329122]")
Next

Open in new window


In my test, my form had the title (Text property) of "Form1". You would change this to exactly match the text of your form. The ID was attained by using the Window Info tool which comes with AutoIT:

Window Info Tool
Within this tool, there is a small target icon. If you've ever used Spy++, then you should have an idea of what this feature does. If you haven't, then you can actually click and drag the little target to any form on your desktop. As you mouse over a form, the border of that form will be highlighted. This will be your active target. Further, you can select specific controls from a form. Likewise to the form, a control's border will highlight when you mouse over it. When you let go of your mouse button, the currently highlighted control's information will be populated within the Window Info window.

The "Title" field is the same text as what I mentioned above for the form, so you could also use this tool to grab that value as well. If you switch to the "Control" tab, as I have in the screenshot above, you will get access to the ID property for the control you selected. This value is what you would put in the script above.

The above script is going to execute "faster than [you] can click with a mouse," and if you need to slow it down a bit, you can include a Sleep call in your script.

e.g.

For $i = 0 To 10
  ControlClick("Form1", "", "[ID:656868]")
  Sleep(1000) ' in milliseconds
Next

Open in new window


Realize that the scripting language is VB/VBA-esque. The tool has decent documentation, and since it's similar to VB, you can adapt a lot of VB code to be used within the tool. The tool itself is pretty popular, so even if you get stuck, you should be able to find help with any problems you encounter.

At least it's an option  = )
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you want to do it manually, then you'll need to obtain a handle the panel first.  Do you know how to that?

Assuming so, then you'd use SendMessage() to send a mouse down message (and possibly a follow-up mouse up message depending on what you're doing):

        private const int WM_LBUTTONDOWN = 0x201;

        [DllImport("User32.DLL")]
        private static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

        private void button1_Click(object sender, EventArgs e)
        {
            SendMessage(panel1.Handle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
        }
0
käµfm³d 👽Commented:
For Idle_Mind's method, I believe you would also need FindWindow (maybe FindWindowEx) since you mention the click utility's "external" requirement.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Jacques Bourgeois (James Burger)PresidentCommented:
If this apply to your situation, typically if no other mouse events are involved, you can call the click event from inside the application itself.

Simply add a button or menu on the form to start your test, something that is visible only by an administrator or through a back door if you do not want the users to see it.

Prepare a loop, maybe with a short Sleep instruction to be closer to a reall life situation, and call your event handler in every loop:

Button1_Click (null, null);
0
BlearyEyeAuthor Commented:
Am checking into AutoIT ... JamesBurger: can't add a button to the app since I need to test a deployed version.
0
Jacques Bourgeois (James Burger)PresidentCommented:
As I told you, the button can be hidden by a backdoor so that only you have access to it for your tests.

A nice thing about that feature is that you can still test at the users station after the application is deployed if you find problems on some of the computers. The user will never see the button. And a hidden button or menu with the simple code that the test would require does not add a significant overhead to the application.
0
BlearyEyeAuthor Commented:
After a bit of effort, AutoIT did the trick. Nice tool. I had to use MouseClick rather than ControlClick, for some reason that I did not quite divine; the control in question has a MouseDown event that changes the focus, as well as a Click event.

Idle_Mind's solution would also have worked, tho it would have required a C# app which is a bit more complex.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

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.