Sign in to follow this  
Followers 0
sesk

ControlClick C# call not working, script ControlClick working

1 post in this topic

#1 ·  Posted (edited)

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

[DllImport("user32.dll")]
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 ?

Edited by sesk

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  
Followers 0