原文: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的更多相关文章

  1. wpf 模拟3D效果(和手机浏览图片效果相似)(附源码)

    原文 wpf 模拟3D效果(和手机浏览图片效果相似)(附源码) pf的3D是一个很有意思的东西,类似于ps的效果,类似于电影动画的效果,因为动画的效果,(对于3D基础的摄像机,光源,之类不介绍,对于依 ...

  2. iOS Programming Touch Events and UIResponder

    iOS Programming Touch Events and UIResponder  1 Touch Events  As a subclass of UIResponder, a UIView ...

  3. js模拟触发事件

     html标签元素封装着实用的[事件],但在很多时候,需要[模拟触发事件],比如 [按钮单机事件]  可以实实在在点击按钮触发该事件,但体验而言,很多时候需要js逻辑处理让实现 触发事件的效果这时就用 ...

  4. [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 ...

  5. WPF 模拟UI 键盘录入

    原文:WPF 模拟UI 键盘录入 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/yangyisen0713/article/details/1835 ...

  6. WPF模拟探照灯文字

    原文:WPF模拟探照灯文字 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/yangyisen0713/article/details/1835936 ...

  7. WPF模拟雷达界面效果图

    原文:WPF模拟雷达界面效果图 iPad塔防的防守兵的效果很炫,2个小时用WPF模拟了一个. 效果图: 关键代码: <Grid> <Grid.Background> <I ...

  8. WPF模拟Office2010文件菜单的TabControl模板

    原文:WPF模拟Office2010文件菜单的TabControl模板 这是Office2010中的文件菜单点开后的效果.本文我将以强大的WPF(www.itstrike.cn)来实现类似的效果.希望 ...

  9. wpf 模拟抖音很火的罗盘时钟,附源码,下载就能跑

    wpf 模拟抖音很火的罗盘时钟,附源码 前端时间突然发现,抖音火了个壁纸,就是黑底蕾丝~~~  错错错,黑底白字的罗盘时钟! 作为程序员的我,也觉得很新颖,所以想空了研究下,这不,空下来了就用wpf, ...

随机推荐

  1. ios开发多线程二:NSOperationQueue的基本使用

    #import "ViewController.h" #import "XMGOperation.h" @interface ViewController () ...

  2. 修改VNC的分辨率

    http://blog.csdn.net/jlds123/article/details/9064437 有时候用VNC View打开远程linux桌面时,桌面显示不出来,只有一个灰色背景加上一个命令 ...

  3. 【60.97%】【BZOJ 1925】 [Sdoi2010]地精部落

    Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 1194  Solved: 728 [Submit][Status][Discuss] Descript ...

  4. Hudson版本控制 (备注)

    http://www.ttlsa.com/tools/install-hudson-on-linux/

  5. ITFriend创业败局(序):简要概述我的第一次创业经历

    是时候, 面对过去,继续踏上未来之路了.    是时候,该给自己一个交待了,给ITFriend创业合伙人.ITFriend用户.关注我的朋友和网友们一个答复了.    是时候,全面认真总结过去的经历. ...

  6. bat文件从@含义起

    今天看到一个批处理文件,内容很简单,执行很方便,学习了一下才知道就是一条条的dos命令, 掌握其中的几个常用命令能看懂别人的文件就行了 1.@ 一般紧随其后 类似@echo off 其作用类似于ech ...

  7. CF439E:The Untended Antiquity - 哈希 + 二维树状数组

    Magic Door 题目大意 有一个n*m的网格,支持三中操作: 1.在x1,y1,x2,y2为顶点的矩形周围围上栅栏 2.将x1,y1,x2,y2为顶点的矩形周围的栅栏拆掉 3.询问x1,y1,x ...

  8. 【codeforces 779B】Weird Rounding

    [题目链接]:http://codeforces.com/contest/779/problem/B [题意] 问你要删掉几个数字才能让原来的数字能够被10^k整除; [题解] /* 数字的长度不大; ...

  9. 【LCA最近公共祖先】在线离线

    [在线] 1.倍增法 现将深度较大的跳至与深度较小的统一深度.预处理$fa[u][i]$表示$u$往上跳$2^i$个单位后的祖先,则就可以像快速幂一样,将移动的步数化为二进制,如果第$i$位为$1$, ...

  10. Spring MVC的RequestContextHolder使用误区 good

    JShop简介:jshop是一套使用Java语言开发的B2C网店系统,致力于为个人和中小企业提供免费.好用的网店系统. 项目主页:http://git.oschina.net/dinguangx/js ...