Autoit Control Click Using C
Sends a mouse click command to a given control.
ControlClick ( "title", "text", controlID [, button [,
clicks [, x [, y]]]] )
Parameters
title | The title of the window to access. |
text | The text of the window to access. |
controlID | The control to interact with. See Controls. |
button | [optional] The button to click, "left", "right", "middle", "main", "menu", "primary", "secondary". Default is the left button. |
clicks | [optional] The number of times to click the mouse. Default is 1. |
x | [optional] The x position to click within the control. Default is center. |
y | [optional] The y position to click within the control. Default is center. |
Return Value
Success: | Returns 1. |
Failure: | Returns 0. |
Remarks
Some controls will resist clicking unless they are the active window. Use the WinActivate() function to force the control's window to the top before using ControlClick().Using 2 for the number of clicks will send a double-click message to the control - this can even be used to launch programs from an explorer control!
If the user has swapped the left and right mouse buttons in the control panel, then the behaviour of the buttons is different. "Left" and "right" always click those buttons, whether the buttons are swapped or not. The "primary" or "main" button will be the main click, whether or not the buttons are swapped. The "secondary" or "menu" buttons will usually bring up the context menu, whether the buttons are swapped or not.
Button | Normal | Swapped |
"" | Left | Left |
"left" | Left | Left |
"middle" | Middle | Middle |
"right" | Right | Right |
"primary" | Left | Right |
"main" | Left | Right |
"secondary" | Right | Left |
"menu" | Right | Left |
Source : Autoit Help Document
Example code Using c#
Parameters required :
Title : [CLASS:SciCalc]
Text : ""
Control : left
Button : Button5
NumClick : 1
X : 16
Y : 14
For example we will use a calculator and click some numbers.
Added this script into project :
private void Click(string strButton, int nNumClicks, int nX, int nY, string strControl, int nSleep, string strWindow)
{
_AutoIT.ControlClick(strWindow, "", strControl, strButton, nNumClicks, nX, nY);
for (int i = 0; i < (nSleep / 100); i++)
{
Application.DoEvents();
Thread.Sleep(100);
}
}
Run the command :
private void controlClickButton_Click(object sender, EventArgs e)
{
//open calculator program
autoit.Run("calc.exe", "", 3);
Thread.Sleep(1000);
//click number 7
Click("left", 1, 16, 14, "Button5", 1000, "[CLASS:SciCalc]");
//click number 3
Click("left", 1, 19, 14, "Button15", 1000, "[CLASS:SciCalc]");
}
Download Full Source Code
how to click a button in autoit without using coordinates
ReplyDelete