【发布时间】:2019-02-23 09:41:30
【问题描述】:
如果我按下一个按钮,我想模拟一个 mouscick。 鼠标点击应该在同一程序代码中的 windowsforms Webbrowser 元素上执行。它也不应该移动我自己的鼠标(有线鼠标)。到目前为止,我的问题是它移动了鼠标。最后,即使 Formapplication 被最小化,我也希望这种情况发生。 这是我尝试过的代码:
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}");
}
找不到这样有效的帖子:(
【问题讨论】:
标签: c# windows forms click mouse