c# 在WebBrowser中用SendMessage模拟鼠标点击

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; 

namespace BrowserMouseClick
{
public partial class Form1 : Form
{
     [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
     static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); 

     [DllImport("user32.dll", SetLastError = true)]
     static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); 

     [DllImport("user32.dll", CharSet = CharSet.Auto)]
     static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); 

     public Form1()
     {
         InitializeComponent();
     } 

     private void Form1_Load(object sender, EventArgs e)
     {
         webBrowser1.Navigate("http://www.devpub.com");
     } 

     private void btnMouseClick_Click(object sender, EventArgs e)
     {
         int x = 100; // X coordinate of the click
         int y = 80; // Y coordinate of the click
         IntPtr handle = webBrowser1.Handle;
         StringBuilder className = new StringBuilder(100);
         while (className.ToString() != "Internet Explorer_Server") // The class control for the browser
         {
             handle = GetWindow(handle, 5); // Get a handle to the child window
             GetClassName(handle, className, className.Capacity);
         } 

         IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates
         IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
         const uint downCode = 0x201; // Left click down code
         const uint upCode = 0x202; // Left click up code
         SendMessage(handle, downCode, wParam, lParam); // Mouse button down
         SendMessage(handle, upCode, wParam, lParam); // Mouse button up
     }
}
}

  

时间: 2024-08-08 17:49:29

c# 在WebBrowser中用SendMessage模拟鼠标点击的相关文章

sendmessage()模拟鼠标点击

{鼠标软模拟:好处就是不会真的移动鼠标 开始按钮 坐标 x=386y=387 }sendmessage(hookHwnd,messages.WM_LBUTTONDOWN ,0,$0180017A); {按下鼠标左键}sendmessage(hookHwnd,messages.WM_LBUTTONUP ,0, $0180017A); {抬起鼠标左键}{硬件模拟:会真的移动鼠标}mouse_event(MOUSEEVENTF_LEFTDOWN,X ,Y ,0,0);mouse_event(MOUSE

使用JS或jQuery模拟鼠标点击a标签事件代码

原文 使用JS或jQuery模拟鼠标点击a标签事件代码 这篇文章主要介绍了使用JS或jQuery模拟鼠标点击a标签事件代码,需要的朋友可以参考下 <a id="alink" href="abc.aspx" style="visibility: hidden;">下一步</a> $("#alink").click(); // 触发了a标签的点击事件,但是没有触发页面跳转 document.getEleme

python模拟鼠标点击window图标

#python模拟点击是通过pymouse实现的,首先要安装pymouse. pip install python-xlib pip install pymouse #安装win32api: http://down.51cto.com/data/2326324 #python打开windos程序的方式: #coding=utf-8 import os os.startfile('E:\youxi\Correspond.exe') #python pymouse的简单应用: #python模拟鼠标

C# 使用Win32API移动光标至指定位置并模拟鼠标点击

东西不难. 使用的函数那么几个. 本例是我删除淘宝购物记录时写的,所以是两个坐标点来回移动并点击鼠标左键. using System; using System.Runtime.InteropServices; using System.Threading; namespace 鼠标移动且点击 { public enum MouseType { //移动鼠标 MOUSEEVENTF_MOVE = 0x0001, //模拟鼠标左键按下 MOUSEEVENTF_LEFTDOWN = 0x0002,

使用jQuery模拟鼠标点击a标签事件

来源于:https://mo2g.com/view/42/ <html> <head> <meta charset="UTF-8"> <title>磨途歌-A标签测试3</title> </head> <body> <a href="http://www.mo2g.com">磨途歌</a> </body> </html> <scr

模拟鼠标点击

function fakeClick(fn) { var $a = $('<a href="#" id="fakeClick"></a>'); $a.bind("click", function(e) { e.preventDefault(); fn(); }); $("body").append($a); var evt,el = $("#fakeClick").get(0); i

Python 模拟鼠标点击

原文:https://blog.csdn.net/weixin_38917807/article/details/81667041 原文:https://blog.csdn.net/weixin_41561539/article/details/94294828 pip安装库: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pymouse pip install -i https://pypi.tuna.tsinghua.edu.

远程控制篇:用Delphi模拟键盘输入/鼠标点击

模拟键盘我们用Keybd_event这个api函数,模拟鼠标按键用mouse_event函数. Keybd_event函数能触发一个按键事件,也就是会产生一个WM_KEYDOWN或WM_KEYUP消息,一般用这两个消息来模拟一 次按键(按键的过程是:按下,然后弹起),但是没有直接用这个函数方便.Keybd_event共有四个参数:第一个为按键的虚拟键值,如回车键为vk_return, tab键为vk_tab;第二个参数为扫描码,一般不用设置,用0代替就行;第三个参数为选项标志,如果为keydow

delphi7 怎么让button按钮跟着鼠标点击dbgrideh数据行移动

delphi7 怎么让button按钮跟着鼠标点击dbgrideh数据行移动 在 dbgrid的DBGridCellClick 事件中加上: Delphi/Pascal code 1 2 3 4 5 6 7 8 9 10 11 var   x, y : integer ;   P: TPoint; begin   GetCursorPos(P);   Edit1.Text := Format('X: %d, Y: %d',[P.X, P.Y]);   x := frMainTest.Left ;