[Flags]
enum MouseEventFlag : uint //设置鼠标动作的键值
{
Move = 0x0001, //发生移动
LeftDown = 0x0002, //鼠标按下左键
LeftUp = 0x0004, //鼠标松开左键
RightDown = 0x0008, //鼠标按下右键
RightUp = 0x0010, //鼠标松开右键
MiddleDown = 0x0020, //鼠标按下中键
MiddleUp = 0x0040, //鼠标松开中键
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800, //鼠标轮被移动
VirtualDesk = 0x4000, //虚拟桌面
Absolute = 0x8000
}

//设置当前鼠标位置

[DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);

//操作鼠标,第一个函数定义操作类型,包括移动,单击双击等

[DllImport("user32.dll")]
static extern bool mouse_event(MouseEventFlag flags, int x,int y,uint data,UIntPtr extraInfo);

[DllImport("USER32.DLL")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

public static void MouseClick()
{
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
}

public static void MouseDoubleClick()
{
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
Thread.Sleep(50);
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
}

public static void MouseRightClick()
{
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
}

public static void MouseDoubleRightClick()
{
mouse_event(MouseEventFlag.RightDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.RightUp, 0, 0, 0, UIntPtr.Zero);
Thread.Sleep(50);
mouse_event(MouseEventFlag.RightDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.RightUp, 0, 0, 0, UIntPtr.Zero);
}

public static void SetString(int x,int y,string input)
{
Thread.Sleep(50);
SetCursorPos(x, y);
Thread.Sleep(50);

MouseClick();

Thread.Sleep(50);

Clipboard.SetText(input);

keybd_event(0xA2, 0, 0, 0);
keybd_event(0x56, 0, 0, 0);
keybd_event(0x56, 0, 2, 0);
keybd_event(0xA2, 0, 2, 0);
}

C# 模拟鼠标操作的更多相关文章

  1. windows7如何用键盘模拟鼠标操作

    windows7如何用键盘模拟鼠标操作 https://jingyan.baidu.com/article/6dad5075104907a123e36e38.html 听语音 37453人看了这个视频 ...

  2. 模拟鼠标操作(ActionChains)(转 侵删)

    在日常的测试中,经常会遇到需要鼠标去操作的一些事情,比如说悬浮菜单.拖动验证码等,这一节我们来学习如何使用webdriver模拟鼠标的操作 首页模拟鼠标的操作要首先引入ActionChains的包 f ...

  3. Python+Selenium自动化 模拟鼠标操作

    Python+Selenium自动化 模拟鼠标操作   在webdriver中,鼠标的一些操作如:双击.右击.悬停.拖动等都被封装在ActionChains类中,我们只用在需要使用的时候,导入这个类就 ...

  4. selenium模拟鼠标操作

    Selenium提供了一个类ActionChains来处理模拟鼠标事件,如单击.双击.拖动等. 基本语法: class ActionChains(object): """ ...

  5. webdriver模拟鼠标操作

    ActionChains 生成模拟用户操作的对象 from selenium.webdriver.common.action_chains import ActionChains ActionChai ...

  6. python+selenium模拟鼠标操作

    from selenium.webdriver.common.action_chains import ActionChains #导入鼠标相关的包 ------------------------- ...

  7. Java+selenium之WebDriver模拟鼠标键盘操作(六)

    org.openqa.selenium.interactions.Actions类,主要定义了一些模拟用户的鼠标mouse,键盘keyboard操作.对于这些操作,使用 perform()方法进行执行 ...

  8. selenium webdriver从安装到使用(python语言),显示等待和隐性等待用法,切换窗口或者frame,弹框处理,下拉菜单处理,模拟鼠标键盘操作等

    selenium的用法 selenium2.0主要包含selenium IDE 和selenium webDriver,IDE有点类似QTP和LoadRunner的录制功能,就是firefox浏览器的 ...

  9. Selenium_模拟键盘和鼠标操作(9)

    模拟键盘键盘和鼠标操作主要使用到selenium的keys包,源码如下 class Keys(object): """ Set of special keys codes ...

随机推荐

  1. [UE4]基于物理的材质

    基于物理的材质可以产生更准确并且通常更加自然的外观,在所有照明环境中都可以同样完美地工作! 官方说明

  2. [UE4]使用材质将图片变成黑白

    拖动到材质界面不放,会自动切换到材质界面: 拖放到视图窗口,放开鼠标,就会自动生成一个“Texture Sample”节点 图片材质使用方法跟直接使用图片素材一样:

  3. win7右键菜单调整顺序

    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ Discardable\PostSetup\ShellNew ...

  4. vue和react动画区别

    触发动画 vue触发动画是 v-show,v-if ,动态组件或者组件的根节点 react 是CSSTransition上的属性 in 是true 或false触发动画

  5. angularjs的ng-class

    <!--第一种 直接加变量--> <div ng-class="tempClass"></div> <!--第二种 用{{}} 包住的变量 ...

  6. CheckedListBox  数据绑定

    CheckedListBox  数据绑定方式有多总,常用的绑定方式总结如下: 1.  Items.Add 通过 Itemes.Add 方法来向 CheckedListBox  中添加项 2. Data ...

  7. 解决从客户端(Content="<div><p ><p>12312...")中检测到有潜在危险的Request.Form 值。

    [HttpPost] [ValidateInput(false)]//解决从客户端(Content="<div><p ><p>12312..." ...

  8. 安装hyperledger fabric V1.0.0-beta

      安装文档位置: https://github.com/hyperledger/fabric   fabric代码托管地址 https://hyperledger-fabric.readthedoc ...

  9. tornado运行提示OSError: [WinError 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。

    找到占用端口的进程,kill掉 netstat -ano | find $(port) kill: tskill $(PID)

  10. Implement a deployment tool such as Ansible, Chef, Puppet, or Salt to automate deployment and management of the production environment

    Implement a deployment tool such as Ansible, Chef, Puppet, or Salt to automate deployment and manage ...