日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

WPF- 模拟触发Touch Events

發布時間:2024/10/12 asp.net 118 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

總結

以上是生活随笔為你收集整理的WPF- 模拟触发Touch Events的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。