Best FlaUI code snippet using FlaUI.Core.Input.Touch.CreatePointerTouch
Touch.cs
Source:Touch.cs
...29 /// Performs a tap on the given point or points.30 /// </summary>31 public static void Tap(params Point[] points)32 {33 var contacts = points.Select((p, i) => CreatePointerTouch(p, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT, (uint)i)).ToArray();34 InjectTouchInput(contacts);35 Wait.UntilInputIsProcessed();36 ReleaseContacts(contacts);37 }38 /// <summary>39 /// Holds the touch on the given points for the given duration.40 /// </summary>41 /// <param name="duration">The duration of the hold.</param>42 /// <param name="points">The points that should be hold down.</param>43 public static void Hold(TimeSpan duration, params Point[] points)44 {45 var contacts = points.Select((p, i) => CreatePointerTouch(p, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT, (uint)i)).ToArray();46 InjectTouchInput(contacts);47 Wait.UntilInputIsProcessed();48 // Loop to update the touch points49 var stopwatch = Stopwatch.StartNew();50 while (stopwatch.Elapsed < duration)51 {52 Thread.Sleep(DefaultInterval);53 for (var i = 0; i < points.Length; i++)54 {55 contacts[i].pointerInfo.pointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;56 }57 InjectTouchInput(contacts);58 }59 ReleaseContacts(contacts);60 }61 /// <summary>62 /// Performs a pinch with two fingers.63 /// </summary>64 /// <param name="center">The center point of the pinch.</param>65 /// <param name="startRadius">The starting radius.</param>66 /// <param name="endRadius">The end radius.</param>67 /// <param name="duration">The duration of the action.</param>68 /// <param name="angle">The angle of the two points, relative to the x-axis.</param>69 public static void Pinch(Point center, double startRadius, double endRadius, TimeSpan duration, double angle = 45)70 {71 // Prepare the points72 var startPoints = CreatePointsAround(center, startRadius, angle);73 var endPoints = CreatePointsAround(center, endRadius, angle);74 var startEndPoints = new[]75 {76 Tuple.Create(startPoints[0], endPoints[0]),77 Tuple.Create(startPoints[1], endPoints[1])78 };79 // Perform the Transition80 Transition(duration, startEndPoints);81 }82 /// <summary>83 /// Transitions all the points from the start point to the end points.84 /// </summary>85 /// <param name="duration">The duration for the action.</param>86 /// <param name="startEndPoints">The list of start/end point tuples.</param>87 public static void Transition(TimeSpan duration, params Tuple<Point, Point>[] startEndPoints)88 {89 // Simulate the touch-down on the starting points.90 var contacts = startEndPoints.Select((p, i) => CreatePointerTouch(p.Item1, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT, (uint)i)).ToArray();91 InjectTouchInput(contacts);92 Wait.UntilInputIsProcessed();93 // Interpolate between the start and end point and update the touch points94 Interpolation.Execute(points =>95 {96 for (var i = 0; i < points.Length; i++)97 {98 contacts[i].pointerInfo.pointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;99 contacts[i].pointerInfo.ptPixelLocation = points[i].ToPOINT();100 }101 InjectTouchInput(contacts);102 },103 startEndPoints, duration, DefaultInterval, true);104 Wait.UntilInputIsProcessed();105 ReleaseContacts(contacts);106 }107 /// <summary>108 /// Performs a touch-drag from the start point to the end point.109 /// </summary>110 /// <param name="duration">The duration of the action.</param>111 /// <param name="startPoint">The starting point of the drag.</param>112 /// <param name="endPoint">The end point of the drag.</param>113 public static void Drag(TimeSpan duration, Tuple<Point, Point>[] startEndPoints, TimeSpan durationHold)114 {115 // Simulate the touch-down on the starting points.116 var contacts = startEndPoints.Select((p, i) => CreatePointerTouch(p.Item1, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT, (uint)i)).ToArray();117 InjectTouchInput(contacts);118 Wait.UntilInputIsProcessed();119 // Interpolate between the start and end point and update the touch points120 var stopwatch = Stopwatch.StartNew();121 while (stopwatch.Elapsed < durationHold)122 {123 Thread.Sleep(DefaultInterval);124 for (var i = 0; i < contacts.Length; i++)125 {126 contacts[i].pointerInfo.pointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;127 }128 InjectTouchInput(contacts);129 }130 Interpolation.Execute(points =>131 {132 for (var i = 0; i < points.Length; i++)133 {134 contacts[i].pointerInfo.pointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;135 contacts[i].pointerInfo.ptPixelLocation = points[i].ToPOINT();136 }137 InjectTouchInput(contacts);138 },139 startEndPoints, duration, DefaultInterval, true);140 Wait.UntilInputIsProcessed();141 ReleaseContacts(contacts);142 }143 /// <summary>144 /// Performs a 2-finger rotation around the given point where the first finger is at the center and145 /// the second is rotated around.146 /// </summary>147 /// <param name="center">The center point of the rotation.</param>148 /// <param name="radius">The radius of the rotation.</param>149 /// <param name="startAngle">The starting angle (in rad).</param>150 /// <param name="endAngle">The ending angle (in rad).</param>151 /// <param name="duration">The total duration for the transition.</param>152 public static void Rotate(Point center, double radius, double startAngle, double endAngle, TimeSpan duration)153 {154 // Simulate the touch-down on the starting points.155 var contacts = new[]156 {157 CreatePointerTouch(center, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT, 0),158 CreatePointerTouch(Interpolation.GetNewPoint(center, radius, startAngle), PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT, 1)159 };160 InjectTouchInput(contacts);161 Wait.UntilInputIsProcessed();162 // Interpolate between the start and end point and update the touch points163 Interpolation.ExecuteRotation(point =>164 {165 contacts[0].pointerInfo.pointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;166 contacts[1].pointerInfo.pointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;167 contacts[1].pointerInfo.ptPixelLocation = point.ToPOINT();168 InjectTouchInput(contacts);169 },170 center, radius, startAngle, endAngle, duration, DefaultInterval, true);171 Wait.UntilInputIsProcessed();172 ReleaseContacts(contacts);173 }174 private static void ReleaseContacts(POINTER_TOUCH_INFO[] contacts)175 {176 for (var i = 0; i < contacts.Length; i++)177 {178 contacts[i].pointerInfo.pointerFlags = PointerFlags.UP;179 }180 InjectTouchInput(contacts.ToArray());181 Wait.UntilInputIsProcessed();182 }183 /// <summary>184 /// Create two points around the given center points.185 /// </summary>186 /// <param name="center">The center point.</param>187 /// <param name="radius">The radius.</param>188 /// <param name="angle">The angle to the x axis.</param>189 /// <returns>An array of the two points.</returns>190 private static Point[] CreatePointsAround(Point center, double radius, double angle)191 {192 var v = new Size((int)(radius * Math.Cos(angle * Math.PI / 180)), (int)(radius * Math.Sin(angle * Math.PI / 180)));193 return new[] {194 center + v,195 center - v196 };197 }198 /// <summary>199 /// Helper method to create the most used <see cref="POINTER_TOUCH_INFO"/> structure.200 /// </summary>201 /// <param name="point">The point where the touch action occurs.</param>202 /// <param name="flags">The flags used for the touch action</param>203 /// <param name="id">The id of the point, only needed when more than one.</param>204 /// <returns>A <see cref="POINTER_TOUCH_INFO"/> structure.</returns>205 private static POINTER_TOUCH_INFO CreatePointerTouch(Point point, PointerFlags flags, uint id = 0)206 {207 var touchPoint = point.ToPOINT();208 var contact = new POINTER_TOUCH_INFO209 {210 pointerInfo =211 {212 pointerType = PointerInputType.PT_TOUCH,213 pointerFlags = flags,214 ptPixelLocation = touchPoint,215 pointerId = id,216 },217 touchFlags = TouchFlags.NONE,218 touchMask = TouchMask.NONE,219 rcContact = new RECT...
CreatePointerTouch
Using AI Code Generation
1using FlaUI.Core;2using FlaUI.Core.Input;3using FlaUI.Core.WindowsAPI;4using FlaUI.UIA2;5using FlaUI.UIA3;6using System;7using System.Collections.Generic;8using System.Linq;9using System.Text;10using System.Threading.Tasks;11{12 {13 static void Main(string[] args)14 {15 Application app = Application.Attach("Notepad");16 var automation = new UIA3Automation();17 var window = app.GetMainWindow(automation);18 var button = window.FindFirstDescendant(cf => cf.ByAutomationId("Button1"));19 button.AsButton().Click();20 var edit = window.FindFirstDescendant(cf => cf.ByAutomationId("Edit1"));21 edit.AsTextBox().Text = "Hello World";22 var touch = new Touch();23 var pt = edit.GetClickablePoint();24 var point = new System.Drawing.Point((int)pt.X, (int)pt.Y);25 touch.CreatePointerTouch(new[] { point }, new[] { false });26 Console.WriteLine("Done");27 Console.ReadLine();28 }29 }30}
CreatePointerTouch
Using AI Code Generation
1using FlaUI.Core;2using FlaUI.Core.Input;3using FlaUI.Core.WindowsAPI;4using System;5using System.Threading;6{7 {8 static void Main(string[] args)9 {10 var app = FlaUI.Core.Application.Launch(@"C:\Windows\System32\calc.exe");11 Thread.Sleep(2000);12 var window = app.GetMainWindow(FlaUI.Core.Automation.AutomationFactory.GetDefault());13 var textBox = window.FindFirstDescendant(FlaUI.Core.Definitions.TreeScope.Descendants, FlaUI.Core.Definitions.ConditionFactory.ByAutomationId("Display"));14 var touchPointer = Touch.CreatePointerTouch();15 var rect = textBox.BoundingRectangle;16 var center = rect.Center;17 touchPointer.MoveTo(center);18 touchPointer.Press();19 Thread.Sleep(1000);20 touchPointer.Release();21 Thread.Sleep(1000);22 app.Close();23 }24 }25}26using FlaUI.Core;27using FlaUI.Core.Input;28using FlaUI.Core.WindowsAPI;29using System;30using System.Threading;31{32 {33 static void Main(string[] args)34 {35 var app = FlaUI.Core.Application.Launch(@"C:\Windows\System32\calc.exe");36 Thread.Sleep(2000);37 var window = app.GetMainWindow(FlaUI.Core.Automation.AutomationFactory.GetDefault());38 var textBox = window.FindFirstDescendant(FlaUI.Core.Definitions.TreeScope.Descendants, FlaUI.Core.Definitions.ConditionFactory.ByAutomationId("Display"));39 var touchPointer = Touch.CreatePointerTouch();
CreatePointerTouch
Using AI Code Generation
1using FlaUI.Core;2using FlaUI.Core.Input;3using FlaUI.Core.WindowsAPI;4using System;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9using System.Windows.Forms;10{11 {12 static void Main(string[] args)13 {14 var app = Application.Launch(@"C:\Windows\System32\notepad.exe");15 var automation = new UIA3Automation();16 Touch touch = new Touch(automation);17 var window = app.GetMainWindow(automation);18 var windowRectangle = window.Properties.BoundingRectangle.Value;19 var x = windowRectangle.X + 100;20 var y = windowRectangle.Y + 100;21 touch.CreatePointerTouch(PointerTouchInfo.PointerInfoFlags.DOWN, x, y, 0, 1, 1);22 touch.CreatePointerTouch(PointerTouchInfo.PointerInfoFlags.UP, x, y, 0, 1, 1);23 app.Close();24 }25 }26}
CreatePointerTouch
Using AI Code Generation
1using System;2using System.Drawing;3using System.Windows.Forms;4using FlaUI.Core.AutomationElements;5using FlaUI.Core.Input;6using FlaUI.Core.WindowsAPI;7{8 {9 public Form1()10 {11 InitializeComponent();12 }13 private void button1_Click(object sender, EventArgs e)14 {15 Touch.CreatePointerTouch(1, 1, 1, new Point(100, 100), 0);16 }17 }18}
CreatePointerTouch
Using AI Code Generation
1using FlaUI.Core;2using FlaUI.Core.Input;3using FlaUI.Core.WindowsAPI;4using System;5using System.Diagnostics;6{7 {8 static void Main(string[] args)9 {10 var app = Application.Launch(@"C:\Windows\System32\calc.exe");11 var mainWindow = app.GetMainWindow();12 var mainWindowRect = mainWindow.Properties.BoundingRectangle;13 var x = mainWindowRect.X;14 var y = mainWindowRect.Y;15 var height = mainWindowRect.Height;16 var width = mainWindowRect.Width;17 var centerX = x + width / 2;18 var centerY = y + height / 2;19 var touchInputDevice = new TouchInputDevice();20 var pointerTouch = Touch.CreatePointerTouch(1, centerX, centerY);21 touchInputDevice.TouchDown(pointerTouch);22 touchInputDevice.TouchUp(pointerTouch);23 System.Threading.Thread.Sleep(1000);24 app.Close();25 }26 }27}
CreatePointerTouch
Using AI Code Generation
1using FlaUI.Core.Input;2using FlaUI.Core.WindowsAPI;3using System;4using System.Diagnostics;5using System.Windows.Forms;6{7 {8 static void Main(string[] args)9 {10 Process.Start(@"C:\Program Files (x86)\Windows Media Player\wmplayer.exe");11 System.Threading.Thread.Sleep(5000);12 var pointerTouch = new PointerTouch();13 pointerTouch.ContactArea = new FlaUI.Core.Shapes.Rectangle(100, 100, 100, 100);14 pointerTouch.Orientation = 90;15 pointerTouch.Pressure = 100;16 pointerTouch.PointerId = 0;17 pointerTouch.PointerType = PointerType.Touch;18 pointerTouch.PointerFlags = PointerFlags.InRange | PointerFlags.InContact | PointerFlags.Update | PointerFlags.Down;19 Touch.CreatePointerTouch(pointerTouch);20 }21 }22}
CreatePointerTouch
Using AI Code Generation
1using FlaUI.Core.Input;2using FlaUI.Core.WindowsAPI;3using System;4using System.Collections.Generic;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8using System.Windows;9using System.Windows.Input;10{11 {12 static void Main(string[] args)13 {14 var touchPointer = Touch.CreatePointerTouch(1, 100, 100, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT);15 Touch.InjectTouchInput(new[] { touchPointer });16 Touch.InjectTouchInput(new[] { Touch.CreatePointerTouch(1, 100, 100, PointerFlags.UP) });17 }18 }19}20using FlaUI.Core.Input;21using FlaUI.Core.WindowsAPI;22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using System.Windows;28using System.Windows.Input;29{30 {31 static void Main(string[] args)32 {33 var touchPointer = Touch.CreatePointerTouch(1, 100, 100, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT);34 Touch.InjectTouchInput(new[] { touchPointer });35 Touch.InjectTouchInput(new[] { Touch.CreatePointerTouch(1, 100, 100, PointerFlags.UP) });36 }37 }38}39using FlaUI.Core.Input;40using FlaUI.Core.WindowsAPI;41using System;42using System.Collections.Generic;43using System.Linq;44using System.Text;45using System.Threading.Tasks;46using System.Windows;47using System.Windows.Input;48{49 {50 static void Main(string[] args)51 {52 var touchPointer = Touch.CreatePointerTouch(1, 100, 100, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT);
CreatePointerTouch
Using AI Code Generation
1using System;2using System.Threading;3using FlaUI.Core;4using FlaUI.Core.Input;5using FlaUI.Core.AutomationElements;6using FlaUI.Core.Definitions;7using FlaUI.Core.WindowsAPI;8{9 {10 public static void CreatePointerTouch(PointerTouchInfo[] pointerTouchInfo)11 {12 {13 cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(TouchInput)),14 };15 touch.dx = 100;16 touch.dy = 100;17 touch.dwID = 0;18 touch.dwExtraInfo = IntPtr.Zero;19 touch.cxContact = 1;20 touch.cyContact = 1;21 touch.dwTime = 0;22 touch.dwMask = TouchMask.CONTACTAREA | TouchMask.TIMEFROMSYSTEM;23 TouchInput[] touches = new TouchInput[] { touch };24 User32.RegisterTouchWindow(pointerTouchInfo[0].hwnd, 0);25 User32.InjectTouchInput(1, touches);26 }27 }28}29using System;30using System.Threading;31using FlaUI.Core;32using FlaUI.Core.Input;33using FlaUI.Core.AutomationElements;34using FlaUI.Core.Definitions;35using FlaUI.Core.WindowsAPI;36{37 {38 public static void CreatePointerTouch(PointerTouchInfo[] pointerTouchInfo)39 {40 {41 cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(TouchInput)),42 };43 touch.dx = 100;44 touch.dy = 100;45 touch.dwID = 0;46 touch.dwExtraInfo = IntPtr.Zero;47 touch.cxContact = 1;48 touch.cyContact = 1;49 touch.dwTime = 0;50 touch.dwMask = TouchMask.CONTACTAREA | TouchMask.TIMEFROMSYSTEM;
CreatePointerTouch
Using AI Code Generation
1Touch.TouchPointer pointer = Touch.CreatePointerTouch(0, 100, 100);2Touch touch = new Touch();3touch.TouchPointers.Add(pointer);4AutomationElement element = AutomationElement.FromHandle(window);5AutomationElement targetElement = element.FindFirstDescendant(cf => cf.ByControlType(ControlType.Button));6Rectangle rectangle = targetElement.BoundingRectangle;7Touch.TouchPoint touchPoint = new Touch.TouchPoint(rectangle.X, rectangle.Y, TouchAction.Down);8touch.TouchPoints.Add(touchPoint);9touch.Apply();10Touch.TouchPointer pointer = Touch.CreatePointerTouch(0, 100, 100);11Touch touch = new Touch();12touch.TouchPointers.Add(pointer);13AutomationElement element = AutomationElement.FromHandle(window);14AutomationElement targetElement = element.FindFirstDescendant(cf => cf.ByControlType(ControlType.Button));15Rectangle rectangle = targetElement.BoundingRectangle;16Touch.TouchPoint touchPoint = new Touch.TouchPoint(rectangle.X, rectangle.Y, TouchAction.Up);17touch.TouchPoints.Add(touchPoint);18touch.Apply();19Touch.TouchPointer pointer = Touch.CreatePointerTouch(0, 100, 100);20Touch touch = new Touch();21touch.TouchPointers.Add(pointer);22AutomationElement element = AutomationElement.FromHandle(window);23AutomationElement targetElement = element.FindFirstDescendant(cf => cf.ByControlType(ControlType.Button));
CreatePointerTouch
Using AI Code Generation
1using FlaUI.Core;2using FlaUI.Core.Input;3using FlaUI.Core.WindowsAPI;4using System;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9{10 {11 static void Main(string[] args)12 {13 var pointerTouch = Touch.CreatePointerTouch(1, 100, 100);14 TouchInputManager.Instance.ProcessTouchInput(pointerTouch);15 }16 }17}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!