Handle+mouse_event

  • Thread starter Thread starter Abhishek
  • Start date Start date
A

Abhishek

Hi,

how do I pass the handle of a control to the win32 api mouse_event. so
that it will create the click event on that application only even if there
is any other window in front of it. I dont what to set focus. I just want
the click event to happen in that window directly.

Regards
Abhishek
 
Abhishek,

The Handle property on the control will return the handle that you are
looking for.

Hope this helps.
 
Hi Abhishek,

Are you trying to send mouse input to a different process? You'll have to obtain the window handle by enumerating the windows in
the process and view the text and type to find the specific control. There a Win32 API functions that you can use such as
EnumWindows and EnumChildWindows.

To simulate a click in your own application obtain the handle of the control from the Control.Handle property.

In either case after you retrieve the handle pass it to the external SendMessage Win32 API function along with WM_LBUTTONUP.

(Note that a few controls in the framework have a PerformClick method, which will alleviate the need for interop if you can use
them.)
 
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt this
will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);
 
Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the click
event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Dave Sexton said:
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's
handle using the Control.Handle property. I doubt this will work
cross-process but you could try to obtain the handle to a window in
another application using the EnumWindows or EnumChildWindows Win32 API
functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam,
int lparam);


--
Dave Sexton

Abhishek said:
Hi,

how do I pass the handle of a control to the win32 api mouse_event. so
that it will create the click event on that application only even if
there is any other window in front of it. I dont what to set focus. I
just want the click event to happen in that window directly.

Regards
Abhishek
 
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call Application.DoEvents() in that case to allow the Control
some time to process your mouse notifications, however a better program architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully understand the situation.

Do you have two applications running simultaneously and you are attempting to get one application to send a mouse notification to
the other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you are attempting to send a mouse notification to a control on
the unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Abhishek said:
Hi All

Getting the handle of the contol is not the problem. if I have a game running then the mouse event does not function (with
mouse_event). the sendmessage is not working at all, the application gets focus but the click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Dave Sexton said:
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt
this will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);


--
Dave Sexton

Abhishek said:
Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to
happen in that window directly.

Regards
Abhishek
 
Hi Dave,

i am trying to create a ingame brower window. for this my dll is creating
bmp's of the embedded browser which present on a win form. This DLL is
loaded by my proxy directx 9 dll which is called by the game. this give me
real time render. I can watch youtube video's in game without a single
frameskip. the next step for me is the recreate a ingame click on a location
x, y in my browser. so that the navigation happens seamlessly. they are both
one below each other in placement(start x and y for both ingame and out of
game is 0,0 for now).
below are the two functions that should be able to handle this. the
mouse_event work perfectly when the browser is visible on screen.but
otherwise it down not. which is why i wanted to know if you can pass the
handle of the browser like in SendMessage so that the click happens in that.

In sendmessage the form becomes formost but no click happens.
private const int MOUSEEVENTF_LEFTDOWN = 0x2;
private const int MOUSEEVENTF_LEFTUP = 0x4;
private const uint WM_LBUTTONUP = 0x202, WM_LBUTTONDOWN = 0x201;

public unsafe void createleftclick() {
int x = 8, y = 8;
int point = x + (y << 16);
SetCursorPos(8, 8);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
}

public void SendClick(int px, int py)
{
SetCursorPos(25, 25);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));
}

My directx dll will just call the function directly
Regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call
Application.DoEvents() in that case to allow the Control some time to
process your mouse notifications, however a better program architecture
would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully
understand the situation.

Do you have two applications running simultaneously and you are attempting
to get one application to send a mouse notification to the other? If so,
are both apps managed code?
Do you have a single, managed application with two visible Forms and you
are attempting to send a mouse notification to a control on the unfocused
Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Abhishek said:
Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the
click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Dave Sexton said:
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this will
work cross-process but you could try to obtain the handle to a window in
another application using the EnumWindows or EnumChildWindows Win32 API
functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam,
int lparam);


--
Dave Sexton

Hi,

how do I pass the handle of a control to the win32 api mouse_event.
so that it will create the click event on that application only even if
there is any other window in front of it. I dont what to set focus. I
just want the click event to happen in that window directly.

Regards
Abhishek
 
I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call
Application.DoEvents() in that case to allow the Control some time to
process your mouse notifications, however a better program architecture
would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully
understand the situation.

Do you have two applications running simultaneously and you are attempting
to get one application to send a mouse notification to the other? If so,
are both apps managed code?
Do you have a single, managed application with two visible Forms and you
are attempting to send a mouse notification to a control on the unfocused
Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Abhishek said:
Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the
click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Dave Sexton said:
Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this will
work cross-process but you could try to obtain the handle to a window in
another application using the EnumWindows or EnumChildWindows Win32 API
functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam,
int lparam);


--
Dave Sexton

Hi,

how do I pass the handle of a control to the win32 api mouse_event.
so that it will create the click event on that application only even if
there is any other window in front of it. I dont what to set focus. I
just want the click event to happen in that window directly.

Regards
Abhishek
 
Hi abhishek,

Interesting idea but I have no idea what the browser is doing with your messages. Since it is a browser, after all, why not just
call ExecScript and perform a click in the actual browser using something like the following:

<script language="JavaScript">
function performClick(x, y) {
obj = document.elementFromPoint(x, y);
if (obj.click)
obj.click();"
}
</script>

MSDN object.click() method reference:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/click.asp

If you are using the 2.0 framework's WebBrowser control:

browser.Document.InvokeScript("performClick", x, y);

For the ActiveX browser use the ExecScript method from IHTMLWindow2 to call the function.

--
Dave Sexton

Abhishek said:
Hi Dave,

i am trying to create a ingame brower window. for this my dll is creating bmp's of the embedded browser which present on a win
form. This DLL is loaded by my proxy directx 9 dll which is called by the game. this give me real time render. I can watch youtube
video's in game without a single frameskip. the next step for me is the recreate a ingame click on a location x, y in my browser.
so that the navigation happens seamlessly. they are both one below each other in placement(start x and y for both ingame and out
of game is 0,0 for now).
below are the two functions that should be able to handle this. the mouse_event work perfectly when the browser is visible on
screen.but otherwise it down not. which is why i wanted to know if you can pass the handle of the browser like in SendMessage so
that the click happens in that.

In sendmessage the form becomes formost but no click happens.
private const int MOUSEEVENTF_LEFTDOWN = 0x2;
private const int MOUSEEVENTF_LEFTUP = 0x4;
private const uint WM_LBUTTONUP = 0x202, WM_LBUTTONDOWN = 0x201;

public unsafe void createleftclick() {
int x = 8, y = 8;
int point = x + (y << 16);
SetCursorPos(8, 8);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);
}

public void SendClick(int px, int py)
{
SetCursorPos(25, 25);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));
}

My directx dll will just call the function directly
Regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call Application.DoEvents() in that case to allow the Control
some time to process your mouse notifications, however a better program architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully understand the situation.

Do you have two applications running simultaneously and you are attempting to get one application to send a mouse notification to
the other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you are attempting to send a mouse notification to a control
on the unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Abhishek said:
Hi All

Getting the handle of the contol is not the problem. if I have a game running then the mouse event does not function (with
mouse_event). the sendmessage is not working at all, the application gets focus but the click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt
this will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);


--
Dave Sexton

Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to
happen in that window directly.

Regards
Abhishek
 
Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other post) but if it's non-zero that would indicate an error and
you should go from there.

--
Dave Sexton

Abhishek said:
I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call Application.DoEvents() in that case to allow the Control
some time to process your mouse notifications, however a better program architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully understand the situation.

Do you have two applications running simultaneously and you are attempting to get one application to send a mouse notification to
the other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you are attempting to send a mouse notification to a control
on the unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Abhishek said:
Hi All

Getting the handle of the contol is not the problem. if I have a game running then the mouse event does not function (with
mouse_event). the sendmessage is not working at all, the application gets focus but the click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt
this will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);


--
Dave Sexton

Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to
happen in that window directly.

Regards
Abhishek
 
its is returning zero!


Dave Sexton said:
Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other
post) but if it's non-zero that would indicate an error and you should go
from there.

--
Dave Sexton

Abhishek said:
I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call
Application.DoEvents() in that case to allow the Control some time to
process your mouse notifications, however a better program architecture
would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I
fully understand the situation.

Do you have two applications running simultaneously and you are
attempting to get one application to send a mouse notification to the
other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you
are attempting to send a mouse notification to a control on the
unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the
click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this will
work cross-process but you could try to obtain the handle to a window
in another application using the EnumWindows or EnumChildWindows Win32
API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int
wparam, int lparam);


--
Dave Sexton

Hi,

how do I pass the handle of a control to the win32 api
mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I
dont what to set focus. I just want the click event to happen in that
window directly.

Regards
Abhishek
 
cant use the script :(

Since this will just create a event on a link. bit of there is flash open
then? I will get the object of the flash and the click will not happen on
the button that is in the flash. also mouseovers and other stuff will not
happen. I need to create actual in game browser with all the bell and
whistles there is also the issue of scrollbars that need to be dragged

so my best bet is to use something like sendmessage, which is returning
zero. maybe there is a click happening just not at 30,30 the point i am
sending the cursor to.

regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other
post) but if it's non-zero that would indicate an error and you should go
from there.

--
Dave Sexton

Abhishek said:
I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call
Application.DoEvents() in that case to allow the Control some time to
process your mouse notifications, however a better program architecture
would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I
fully understand the situation.

Do you have two applications running simultaneously and you are
attempting to get one application to send a mouse notification to the
other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you
are attempting to send a mouse notification to a control on the
unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event). the
sendmessage is not working at all, the application gets focus but the
click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this will
work cross-process but you could try to obtain the handle to a window
in another application using the EnumWindows or EnumChildWindows Win32
API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int
wparam, int lparam);


--
Dave Sexton

Hi,

how do I pass the handle of a control to the win32 api
mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I
dont what to set focus. I just want the click event to happen in that
window directly.

Regards
Abhishek
 
Hi Abhishek,

Well you still might be able to use scripting if the Flash object model supports simulating a mouse click at a certain point. Check
if Flash also supports raising a mouse over event and scrolling from script while your at it.
so my best bet is to use something like sendmessage, which is returning zero. maybe there is a click happening just not at 30,30
the point i am sending the cursor to.

You must send the point to the SendMessage function. It doesn't matter where the cursor is actually located on the screen for
SendMessage with WM_LBUTTONDOWN.

To verify that SendMessage is working, since it is after all returning zero, why don't you replace the browser with a Button and in
a Click event handler show a MessageBox. Try to click the button with SendMessage. If it works then I suspect the problem is with
the browser and script might be your only option.

--
Dave Sexton

Abhishek said:
cant use the script :(

Since this will just create a event on a link. bit of there is flash open then? I will get the object of the flash and the click
will not happen on the button that is in the flash. also mouseovers and other stuff will not happen. I need to create actual in
game browser with all the bell and whistles there is also the issue of scrollbars that need to be dragged

so my best bet is to use something like sendmessage, which is returning zero. maybe there is a click happening just not at 30,30
the point i am sending the cursor to.

regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other post) but if it's non-zero that would indicate an error and
you should go from there.

--
Dave Sexton

Abhishek said:
I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to call Application.DoEvents() in that case to allow the
Control some time to process your mouse notifications, however a better program architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I fully understand the situation.

Do you have two applications running simultaneously and you are attempting to get one application to send a mouse notification
to the other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and you are attempting to send a mouse notification to a
control on the unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Hi All

Getting the handle of the contol is not the problem. if I have a game running then the mouse event does not function (with
mouse_event). the sendmessage is not working at all, the application gets focus but the click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the control's handle using the Control.Handle property. I doubt
this will work cross-process but you could try to obtain the handle to a window in another application using the EnumWindows
or EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int wparam, int lparam);


--
Dave Sexton

Hi,

how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it. I dont what to set focus. I just want the click event to
happen in that window directly.

Regards
Abhishek
 
Hi Dave

Thanks for all the help finally got it working.
the issue was not with sendmessage. the issue was the since the browser was
a activex control the normal browsername.handle did not work here. I had to
first use getwindow and GetClassName to find out the handle and then use
that in sendmessage.

but thanks a lot. it really helped.

regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Well you still might be able to use scripting if the Flash object model
supports simulating a mouse click at a certain point. Check if Flash also
supports raising a mouse over event and scrolling from script while your
at it.
so my best bet is to use something like sendmessage, which is returning
zero. maybe there is a click happening just not at 30,30 the point i am
sending the cursor to.

You must send the point to the SendMessage function. It doesn't matter
where the cursor is actually located on the screen for SendMessage with
WM_LBUTTONDOWN.

To verify that SendMessage is working, since it is after all returning
zero, why don't you replace the browser with a Button and in a Click event
handler show a MessageBox. Try to click the button with SendMessage. If
it works then I suspect the problem is with the browser and script might
be your only option.

--
Dave Sexton

Abhishek said:
cant use the script :(

Since this will just create a event on a link. bit of there is flash open
then? I will get the object of the flash and the click will not happen on
the button that is in the flash. also mouseovers and other stuff will
not happen. I need to create actual in game browser with all the bell and
whistles there is also the issue of scrollbars that need to be dragged

so my best bet is to use something like sendmessage, which is returning
zero. maybe there is a click happening just not at 30,30 the point i am
sending the cursor to.

regards
Abhishek

Dave Sexton said:
Hi Abhishek,

Does SendMessage return 0 when you send WM_LBUTTONDOWN or UP?

Either way, I think your out of luck with this approach (see my other
post) but if it's non-zero that would indicate an error and you should
go from there.

--
Dave Sexton

I added

rt1 = SendMessage(this.Handle, WM_CLOSE, 0, 0);
the application is closing but the click is not happening
I just cant understand why

Regards
Abhishek

Hi Abhishek,

Is your 'game' by any chance tying up the UI Thread? You'd have to
call Application.DoEvents() in that case to allow the Control some
time to process your mouse notifications, however a better program
architecture would be more appropriate.

Actually, after reviewing your post a second time I'm not so sure I
fully understand the situation.

Do you have two applications running simultaneously and you are
attempting to get one application to send a mouse notification to the
other? If so, are both apps managed code?
Do you have a single, managed application with two visible Forms and
you are attempting to send a mouse notification to a control on the
unfocused Form?

Please clarify. I'd like to help if I can.

--
Dave Sexton

Hi All

Getting the handle of the contol is not the problem. if I have a game
running then the mouse event does not function (with mouse_event).
the sendmessage is not working at all, the application gets focus but
the click event is not happening.

SendMessage(axWebBrowser1.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(axWebBrowser1.Handle, WM_LBUTTONUP, 0, point);


This is the mouse_event
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr(0));
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr(0));

regards
Abhishek

Hi Abhiishek,

Try sending WM_LBUTTONDOWN and then WM_LBUTTONUP and specify the
control's handle using the Control.Handle property. I doubt this
will work cross-process but you could try to obtain the handle to a
window in another application using the EnumWindows or
EnumChildWindows Win32 API functions.

private void SimulateClick(Control ctrl)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");

int x = 8, y = 8;
int point = x + (y << 16);

SendMessage(ctrl.Handle, WM_LBUTTONDOWN, 0, point);
SendMessage(ctrl.Handle, WM_LBUTTONUP, 0, point));
}

private const uint WM_LBUTTONUP = 0x0202, WM_LBUTTONDOWN = 0x0201;

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, uint msg, int
wparam, int lparam);


--
Dave Sexton

Hi,

how do I pass the handle of a control to the win32 api
mouse_event. so that it will create the click event on that
application only even if there is any other window in front of it.
I dont what to set focus. I just want the click event to happen in
that window directly.

Regards
Abhishek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top