I want to simulate a mouscick if I press a button. The mouseclick should be exectuted on the windowsforms Webbrowser element in the same Programm Code. It also should not move my own mouse(cable mouse). My Problem so far is that it moves the mouse. And in the end I want that to happen even if the Formapplication is minimized. Here`s the Code with that I tried it:
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;
public static void LeftMouseClick(int xpos, int ypos)
{
SetCursorPos(xpos, ypos);
mouse_event(MOUSEEVENTF_LEFTDOWN, xpos, ypos, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, xpos, ypos, 0, 0);
}
public Form1()
{
InitializeComponent();
}
private void btnVerbinden_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(txtInternetAdresse.Text);
}
private void MousTest_Click(object sender, EventArgs e)
{
LeftMouseClick(600, 500);
SendKeys.Send("{ENTER}");
}
Coudn`t find a post like this that worked :(