C# 模拟鼠标操作
[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# 模拟鼠标操作的更多相关文章
- windows7如何用键盘模拟鼠标操作
windows7如何用键盘模拟鼠标操作 https://jingyan.baidu.com/article/6dad5075104907a123e36e38.html 听语音 37453人看了这个视频 ...
- 模拟鼠标操作(ActionChains)(转 侵删)
在日常的测试中,经常会遇到需要鼠标去操作的一些事情,比如说悬浮菜单.拖动验证码等,这一节我们来学习如何使用webdriver模拟鼠标的操作 首页模拟鼠标的操作要首先引入ActionChains的包 f ...
- Python+Selenium自动化 模拟鼠标操作
Python+Selenium自动化 模拟鼠标操作 在webdriver中,鼠标的一些操作如:双击.右击.悬停.拖动等都被封装在ActionChains类中,我们只用在需要使用的时候,导入这个类就 ...
- selenium模拟鼠标操作
Selenium提供了一个类ActionChains来处理模拟鼠标事件,如单击.双击.拖动等. 基本语法: class ActionChains(object): """ ...
- webdriver模拟鼠标操作
ActionChains 生成模拟用户操作的对象 from selenium.webdriver.common.action_chains import ActionChains ActionChai ...
- python+selenium模拟鼠标操作
from selenium.webdriver.common.action_chains import ActionChains #导入鼠标相关的包 ------------------------- ...
- Java+selenium之WebDriver模拟鼠标键盘操作(六)
org.openqa.selenium.interactions.Actions类,主要定义了一些模拟用户的鼠标mouse,键盘keyboard操作.对于这些操作,使用 perform()方法进行执行 ...
- selenium webdriver从安装到使用(python语言),显示等待和隐性等待用法,切换窗口或者frame,弹框处理,下拉菜单处理,模拟鼠标键盘操作等
selenium的用法 selenium2.0主要包含selenium IDE 和selenium webDriver,IDE有点类似QTP和LoadRunner的录制功能,就是firefox浏览器的 ...
- Selenium_模拟键盘和鼠标操作(9)
模拟键盘键盘和鼠标操作主要使用到selenium的keys包,源码如下 class Keys(object): """ Set of special keys codes ...
随机推荐
- [UE4]不推荐的UI更新方式
在创建UI的时候,把UI保存到一个变量,直接访问其中的控件. 这种方法会增加耦合,不推荐,应当尽量避免使用这种方式.
- 如何用MAT分析Android程序的内存泄露
本文结合<Android开发艺术探索>书籍中的内存分析例子来讲解如何利用MAT工具来查找内存泄漏(以AndroidStudio开发工具为例). 1.下载MAT(Eclipse Memory ...
- Xmanager远程连接CentOS7
上周例会,又被说了一通,Xmanager远程连接的文档没写?服务没搭建?心想这都有VNC了,为毛一定要弄这个啊?!!但是,我还是在今天给弄了,╮(╯▽╰)╭没人权.搭建完尝试用了下,感觉吧,也不咋地啊 ...
- PostgreSQL手动主从切换
主从切换操作: 1>主库宕机或者测试主备切换情况下停掉主库:systemctl stop postgres 从库会报日志错误信息:[root@db02 /]# cd /var/postgresq ...
- 对KVM虚拟机进行cpu pinning配置的方法
这篇文章主要介绍了对KVM虚拟机进行cpu pinning配置的方法,通过文中的各种virsh命令可进行操作,需要的朋友可以参考下 首先需求了解基本的信息 1 宿主机CPU特性查看 使用virsh n ...
- 各平台免费翻译API
google http://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&s ...
- 查看oracle用户执行的sql语句历史记录
select PARSING_SCHEMA_NAME,COUNT(DISTINCT T.SQL_TEXT) from v$sqlarea t WHERE T.LAST_ACTIVE_TIME > ...
- angularjs路由传递参数
ui-sref.$state.go 的区别 ui-sref 一般使用在 <a>...</a>: $state.go('someState')一般使用在 controller里面 ...
- django总结 --》内容(django建project开始的大致流程、ORM简介)
1 安装: pip install django==1.11.9 另外:在pycharm中安装 django,在下图中七步走 2. 新建Django项目 django-admin startpro ...
- PL/SQL将sql脚本数据导入Oracle
PL/SQL将sql脚本数据导入数据库: 1.首先,使用plsql登录到需要导入数据的数据库.在[tools]--[Import tables] 2.选择第二个[SQL Inserts],在下面,点击 ...