C#模拟按键而不将鼠标移动到Forms Webbrowser

问题描述 投票:0回答:1

如果我按下按钮,我想模拟一个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
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.