WPF- 模拟触发Touch Events
基于API:
[DllImport("User32.dll")]
public static extern bool InitializeTouchInjection(uint maxCount = 256, TouchFeedback feedbackMode = TouchFeedback.DEFAULT);
[DllImport("User32.dll")]
public static extern bool InjectTouchInput(int count, [MarshalAs(UnmanagedType.LPArray), In] PointerTouchInfo[] contacts);
实现效果:点击按钮,自动触发TouchDown事件、获取TouchEventArgs参数得到坐标,创建Line并设置X1、Y1属性,紧接着触发TouchMove、TouchUp事件,得到TouchUp的TouchEventArgs设置Line的X2、Y2属性。
private void MainWindow_TouchUp(object sender, TouchEventArgs e)
{
System.Windows.Input.TouchPoint oPos = e.GetTouchPoint(this);
this.ProxyLine.X2 = oPos.Position.X;
this.ProxyLine.Y2 = oPos.Position.Y;
this.GdRootZm.Children.Add(this.ProxyLine);
Console.WriteLine("TouchID " + e.TouchDevice.Id + " TouchUp "
+ oPos.Position.X + " " + oPos.Position.Y);
}
private void MainWindow_TouchMove(object sender, TouchEventArgs e)
{
System.Windows.Input.TouchPoint oPos = e.GetTouchPoint(this);
Console.WriteLine("TouchID " + e.TouchDevice.Id + " TouchMove "
+ oPos.Position.X + " " + oPos.Position.Y);
}
private Line ProxyLine;
private void MainWindow_TouchDown(object sender, TouchEventArgs e)
{
System.Windows.Input.TouchPoint oPos = e.GetTouchPoint(this);
Line oLine = new Line();
oLine.Stroke = new SolidColorBrush(Colors.Red);
oLine.StrokeThickness = 2;
oLine.X1 = oPos.Position.X;
oLine.Y1 = oPos.Position.Y;
this.ProxyLine = oLine;
Console.WriteLine("TouchID " + e.TouchDevice.Id + " TouchDown "
+ oPos.Position.X + " " + oPos.Position.Y);
}
Console Write Result:
效果图如下:
private void SimulateTouch(int x, int y)
{
// Touch Down Simulate
PointerTouchInfo contact = MakePointerTouchInfo(x, y, 5, 1);
PointerFlags oFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
contact.PointerInfo.PointerFlags = oFlags;
bool bIsSuccess = TouchInjector.InjectTouchInput(1, new[] { contact });
// Touch Move Simulate
int nMoveIntervalX = this.GetRandomSeed().Next(-60, 60);
int nMoveIntervalY = this.GetRandomSeed().Next(-60, 60);
contact.Move(nMoveIntervalX, nMoveIntervalY);
oFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.UPDATE;
contact.PointerInfo.PointerFlags = oFlags;
TouchInjector.InjectTouchInput(1, new[] { contact });
// Touch Up Simulate
contact.PointerInfo.PointerFlags = PointerFlags.UP;
TouchInjector.InjectTouchInput(1, new[] { contact });
}
Source Url:https://github.com/DuelCode/TouchSimulate
Multi Touch Also Support Like this:
private void BdrSimulateZm_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
// Touch Down Simulate
int x1 = this.GetRandomSeed().Next(50, 1680 - 100);
int y1 = this.GetRandomSeed().Next(50, 1080 - 100);
PointerTouchInfo oContact1 = MakePointerTouchInfo(x1, y1, 5, 1);
int x2 = this.GetRandomSeed().Next(50, 1680 - 100);
int y2 = this.GetRandomSeed().Next(50, 1080 - 100);
PointerTouchInfo oContact2 = MakePointerTouchInfo(x2, y2, 5, 1);
PointerFlags oFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
oContact1.PointerInfo.PointerFlags = oFlags;
oContact2.PointerInfo.PointerFlags = oFlags;
TouchInjector.InjectTouchInput(2, new[] { oContact1, oContact2 });
// Touch Move Simulate
int nMoveIntervalX = this.GetRandomSeed().Next(-60, 60);
int nMoveIntervalY = this.GetRandomSeed().Next(-60, 60);
oContact1.Move(nMoveIntervalX, nMoveIntervalY);
oContact2.Move(nMoveIntervalX, nMoveIntervalY);
oFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.UPDATE;
oContact1.PointerInfo.PointerFlags = oFlags;
oContact2.PointerInfo.PointerFlags = oFlags;
TouchInjector.InjectTouchInput(2, new[] { oContact1 , oContact2 });
// Touch Up Simulate
oContact1.PointerInfo.PointerFlags = PointerFlags.UP;
oContact2.PointerInfo.PointerFlags = PointerFlags.UP;
TouchInjector.InjectTouchInput(2, new[] { oContact1, oContact2 });
}
WPF- 模拟触发Touch Events的更多相关文章
- wpf 模拟3D效果(和手机浏览图片效果相似)(附源码)
原文 wpf 模拟3D效果(和手机浏览图片效果相似)(附源码) pf的3D是一个很有意思的东西,类似于ps的效果,类似于电影动画的效果,因为动画的效果,(对于3D基础的摄像机,光源,之类不介绍,对于依 ...
- iOS Programming Touch Events and UIResponder
iOS Programming Touch Events and UIResponder 1 Touch Events As a subclass of UIResponder, a UIView ...
- js模拟触发事件
html标签元素封装着实用的[事件],但在很多时候,需要[模拟触发事件],比如 [按钮单机事件] 可以实实在在点击按钮触发该事件,但体验而言,很多时候需要js逻辑处理让实现 触发事件的效果这时就用 ...
- [React Native] State and Touch Events -- TextInput, TouchableHighLight
In React, components manage their own state. In this lesson, we'll walk through building a component ...
- WPF 模拟UI 键盘录入
原文:WPF 模拟UI 键盘录入 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/yangyisen0713/article/details/1835 ...
- WPF模拟探照灯文字
原文:WPF模拟探照灯文字 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/yangyisen0713/article/details/1835936 ...
- WPF模拟雷达界面效果图
原文:WPF模拟雷达界面效果图 iPad塔防的防守兵的效果很炫,2个小时用WPF模拟了一个. 效果图: 关键代码: <Grid> <Grid.Background> <I ...
- WPF模拟Office2010文件菜单的TabControl模板
原文:WPF模拟Office2010文件菜单的TabControl模板 这是Office2010中的文件菜单点开后的效果.本文我将以强大的WPF(www.itstrike.cn)来实现类似的效果.希望 ...
- wpf 模拟抖音很火的罗盘时钟,附源码,下载就能跑
wpf 模拟抖音很火的罗盘时钟,附源码 前端时间突然发现,抖音火了个壁纸,就是黑底蕾丝~~~ 错错错,黑底白字的罗盘时钟! 作为程序员的我,也觉得很新颖,所以想空了研究下,这不,空下来了就用wpf, ...
随机推荐
- 广播(broadcast)、电视与电视网络
1. 闭路电视与电视 Closed Circuit Television (CCTV) 一种图像通信系统.其信号从源点只传给预先安排好的与源点相通的特定电视机.广泛用于大量不同类型的监视工作.教育.电 ...
- 手机浏览器 input 输入框 数字
其实很简单了啦 type="tel"就行了呢 如果是type="number"其实不好用
- Android JNI编程(四)——C语言多级指针、数组取值、从控制台输入数组
版权声明:本文出自阿钟的博客,转载请注明出处:http://blog.csdn.net/a_zhon/. 目录(?)[+] 一:前面我们介绍了一级指针的相关概念和用发,今天我们就来说一说多级指针. 1 ...
- 【机器学习实战】第4章 朴素贝叶斯(Naive Bayes)
第4章 基于概率论的分类方法:朴素贝叶斯 朴素贝叶斯 概述 贝叶斯分类是一类分类算法的总称,这类算法均以贝叶斯定理为基础,故统称为贝叶斯分类.本章首先介绍贝叶斯分类算法的基础——贝叶斯定理.最后,我们 ...
- php利用反射机制查找类和方法的所在位置
//参数1是类名,参数2是方法名 $func = new ReflectionMethod('UnifiedOrder_pub', 'getPrepayId'); //从第几行开始 $start = ...
- MySQL建立双向主备复制server配置方法
1.环境描写叙述 serverA(主) 192.85.1.175 serverB(从) 192.85.1.176 Mysql版本号:5.1.61 系统版本号:System OS:ubuntu 10.1 ...
- android生成分享长图而且加入全图水印
尊重他人的劳动成果.转载请标明出处:http://blog.csdn.net/gengqiquan/article/details/65938021. 本文出自:[gengqiquan的博客] 领导近 ...
- Qt 打开安卓相冊选择图片并获取图片的本地路径
Qt 打开安卓相冊选择图片并获取图片的本地路径 过程例如以下: 通过 Intent 打开安卓的系统相冊. 推荐使用 QAndroidJniObject::getStaticObjectField 获取 ...
- GTID的限制
1.不支持非事务引擎(从库报错,stop slave;start slave;忽略). 2.不支持create table ... select 语句复制(主库直接报错). 3.不允许一个SQL同时更 ...
- Python 数组[],元组(),字典{}的异同
序列 Python有6中内建的序列,在这里我们重点讨论两种,数组和元组.所有序列都可以做某些特定的操作,大致上常用的是:加,乘,索引,分片以及检查某个元素是否属于序列的成员. Python还提供一些内 ...