I am trying to write a simple Windows form, consisting of buttons, one of the buttons sends mouse clicks to active applications, such as notepad. so I click on the button and the buttons will send mouse events to notepad or any application.
It only sends a right click or click,
I wrote this code for the dll definitions:
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd,uint Msg, int wParam,int lParam);
[DllImport("user32.dll")]
public static extern int FindWindow(String lbClassName, StringlbWindowName);
// for events
private const uint WM_RBUTTONDOWN = 0x0204;
private const uint WM_RBUTTONUP = 0x0205;
// event handler
private void button6_Click(object sender, EventArgs e)
{
int window = FindWindow(null, "Notepad");
SendMessage(window, WM_RBUTTONDOWN, 0, 0);
SendMessage(window, WM_RBUTTONUP, 0, 0);
}
This does not work!
How can I find out that mouse clicks clicked?
And why doesn't it work?
source
share