开发者

Send user input through a windows form

I am looking for a way to pass mouse events through a winform without using Form.TransparencyKey. If there is no simple way t开发者_如何学运维o do this, is there a way to send a mouse event to a given window handle using Win32 API?

Edit By pass through the winform I do not mean to a parent window, I mean to other applications that reside behind mine.


This may sound overkill, as I saw SLaks's answer..

You would need

  1. The handle of the Window using Handle property
  2. Use pinvoke on the SendMessage Win32API
  3. One of the parameters to SendMessage is WM_LBUTTONDOWN

Here's a declaration for the SendMessage

[DllImport("user32")] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

Here's the constants used:

public const int WM_LBUTTONDOWN = 0x201;
public const int WM_LBUTTONUP = 0x202;

Typical Invocation:

SendMessage(someWindow.Handle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(someWindow.Handle, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);

The invocation is an example of how to send a mouse left-click to a specified window.

I used pinvoke.net to obtain the correct API.

Hope this helps, Best regards, Tom.


The answer is actually much easier than I thought it would be. This SO answer got me where I needed to be: Transparent Window (or Draw to screen) No Mouse Capture Also found what looks like a c++ implementation if you want some working code: Transparent Window (or Draw to screen) No Mouse Capture

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜