欢迎访问 生活随笔!

凯发ag旗舰厅登录网址下载

当前位置: 凯发ag旗舰厅登录网址下载 > 编程语言 > asp.net >内容正文

asp.net

wpf-凯发ag旗舰厅登录网址下载

发布时间:2024/10/12 asp.net 26 豆豆
凯发ag旗舰厅登录网址下载 收集整理的这篇文章主要介绍了 wpf- 模拟触发touch events 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
wpf- 模拟触发touch events 原文: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 simulatepointertouchinfo 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 simulateint 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 simulatecontact.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 simulateint 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 simulateint 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 simulateocontact1.pointerinfo.pointerflags = pointerflags.up;ocontact2.pointerinfo.pointerflags = pointerflags.up;touchinjector.injecttouchinput(2, new[] { ocontact1, ocontact2 }); }

 

posted on 2018-08-14 09:17 net未来之路 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/9472580.html

总结

以上是凯发ag旗舰厅登录网址下载为你收集整理的wpf- 模拟触发touch events的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。

  • 上一篇:
  • 下一篇:
网站地图