首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Web自动化鼠标单击

Web自动化鼠标单击
EN

Stack Overflow用户
提问于 2013-07-20 01:32:36
回答 1查看 711关注 0票数 6

我有一个项目,涉及打开多个窗口客户端,然后在每个进程中模拟鼠标点击。我已经能够使用Win32应用编程接口和SendMessage成功地向多个Notepad实例发送消息。适用于我的代码如下:

代码语言:javascript
复制
Process[] notepads = Process.GetProcessesByName("notepad");
            foreach (Process proc in notepads)
            {
                    IntPtr handle = proc.Handle;
                    IntPtr child = FindWindowEx(proc.MainWindowHandle, new IntPtr(0), "Edit", null);
                    if (child != null)
                    {
                        MessageBox.Show("Child was found, sending text");
                        SendMessage(child, 0x000C, 0, "test");
                    }
                }
            }

这将向我打开的记事本的每个实例发送"test“,不管有多少。正如您所看到的,我正在遍历流程的每个实例,并简单地循环消息。一点也不难。

我检索了窗口句柄,然后检索了子(Awesomium)类名,即Chrome_RenderWidgetHostHWND。在那里,我尝试通过重构Sendmessage中的变量类型来发送鼠标事件,以便系统能够进行汇编和lParam读取。以下是代码:

代码语言:javascript
复制
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

代码语言:javascript
复制
int x = 834;
int y = 493;
IntPtr lParam = (IntPtr)((y << 16) | x);
IntPtr wParam = IntPtr.Zero;

我正在使用全局鼠标钩子来检测所有子窗口中的按下事件,当我点击按钮迭代整个过程并单击时,根本不会发送任何内容。我知道我在做一些愚蠢的事情,这会导致鼠标点击不被发送。无论如何,下面是我所拥有的最终代码结构。任何建议或建议都将不胜感激。谢谢。

代码语言:javascript
复制
  private void button2_Click(object sender, EventArgs e)
    {
        Process[] notepads = Process.GetProcessesByName("client");
        foreach (Process proc in notepads)
        {
                IntPtr handle = proc.Handle;
                string mine = Convert.ToString(proc);
                MessageBox.Show(mine);
                IntPtr child = FindWindowEx(proc.MainWindowHandle, new IntPtr(0), "Chrome_RenderWidgetHostHWND", null);
                if (child != null)
                {
                int x = 834;
                int y = 493;
                IntPtr lParam = (IntPtr)((y << 16) | x);
                IntPtr wParam = IntPtr.Zero;
                SendMessage(child, 0x201, wParam, lParam);
                SendMessage(child, 0x202, wParam, lParam);
                }
            }
        }
EN

回答 1

Stack Overflow用户

发布于 2013-08-05 01:14:03

或者,您可以使用SendInput,它可以在有鼠标挂钩的情况下正常工作;您的解决方案(直接发布消息)则不能。

更重要的是,如果进程拒绝激活(即,如果目标从WM_MOUSEACTIVATE返回0),则不会发送WM_LBUTTONDOWN。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17752176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档