?
Solved

Generate clicks for winform app

Posted on 2012-03-25
7
Medium Priority
?
574 Views
Last Modified: 2012-03-27
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#.
0
Comment
Question by:BlearyEye
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1400 total points
ID: 37762902
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
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 600 total points
ID: 37762917
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37762934
For Idle_Mind's method, I believe you would also need FindWindow (maybe FindWindowEx) since you mention the click utility's "external" requirement.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 40
ID: 37763553
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
 
LVL 1

Author Comment

by:BlearyEye
ID: 37771808
Am checking into AutoIT ... JamesBurger: can't add a button to the app since I need to test a deployed version.
0
 
LVL 40
ID: 37771852
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
 
LVL 1

Author Closing Comment

by:BlearyEye
ID: 37775187
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question