Jump to content
Sign in to follow this  

ControlClick C# call not working, script ControlClick working

Recommended Posts


I've got a window point (x,y) I want to click without hogging the mouse pointer. I checked my options out and other than using SendMessage, there's ControlClick.

I made a test script in AutoIt, it works, correct hwnd found, the click occurs.

I ported it to C#, I get the same hwnd, but the click does not occur

Here's the AutoIt Code

#include <WinAPI.au3>

$pos = _WinAPI_GetMousePos()    
$hwnd = _WinAPI_WindowFromPoint($pos)

MsgBox(0, "", $hwnd)

ControlClick($hwnd, "", 0, "left", 1, 526, 31)


And here's the partial C# code

static extern IntPtr WindowFromPoint(POINT point);

Rectangle rct = GetWindowRectangle();//uses AutoItX.WinGetPos
POINT p = new POINT();
p.x = rct.Left + 1;
p.y = rct.Top + 1;
Move(p.x, p.y);
hWnd = WindowFromPoint(p);//hWnd matches the hwnd found in the autoit script

AutoItX.ControlClick(hWnd, IntPtr.Zero, "left", 1, 526, 31);

The only thing I can think of that may be wrong is passing IntPtr.Zero for the control handle. I didn't find any examples using the second definition of ControlClick (windowhandle & controlhandle) so I am unsure.


Anyone with experience with this ?

Share this post

Link to post
Share on other sites

i got no experience with this at all but searching lead me to this Link And this Link they might be related and helpful...

Share this post

Link to post
Share on other sites

Solved it: 

Had to ControlGetHandle on the window

IntPtr ctrlHandle = AutoItX.ControlGetHandle(hWnd);
AutoItX.ControlClick(hWnd, ctrlHandle, "left", 1, x, y);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this