How to use Touch class of FlaUI.Core.Input package

Best FlaUI code snippet using FlaUI.Core.Input.Touch

CalculatorViewShould.cs

Source:CalculatorViewShould.cs Github

copy

Full Screen

...319 rateResult.Should().Be("4.00");320 endResult.Should().Be("5.00");321 }322 [Fact(Skip = "https://github.com/FlaUI/FlaUI/issues/389")]323 public void ShowSavedYearsValue_WhenYearsButtonIsTouchedLong()324 {325 // Arrange326 var mainScreen = this.Application.GetMainWindow(this.Automation);327 // Act328 var resultLbl = WaitForElement(() => mainScreen.FindFirstDescendant(cf => cf.ByAutomationId(UiIds.ClassicCalculator.EvaluationResultLbl)).AsLabel());329 var yearsBtn = WaitForElement(() => mainScreen.FindFirstDescendant(cf => cf.ByAutomationId(UiIds.ClassicCalculator.YearsBtn)).AsButton());330 Mouse.MoveTo(yearsBtn.GetClickablePoint());331 Touch.Hold(this.touchDelayWithOffset, yearsBtn.GetClickablePoint());332 Wait.UntilInputIsProcessed(this.touchDelayWithOffset);333 // Assert334 resultLbl.Text.Should().Be("0.00");335 }336 #region protected Overrides337 protected override AutomationBase GetAutomation()338 {339 var automation = new UIA3Automation();340 return automation;341 }342 protected override Application StartApplication()343 {344 var application = Application.Launch(this.AppPath);345 application.WaitWhileMainHandleIsMissing();...

Full Screen

Full Screen

Touch.cs

Source:Touch.cs Github

copy

Full Screen

...9using FlaUI.Core.WindowsAPI;10namespace FlaNium.Desktop.Driver.Input11{12 /// <summary>13 /// Touch class to simulate touch input.14 /// </summary>15 public static class Touch16 {17 /// <summary>18 /// The interval that is used for interpolation/rotation.19 /// </summary>20 public static TimeSpan DefaultInterval = TimeSpan.FromMilliseconds(50);21 static Touch()22 {23 if (!User32.InitializeTouchInjection())24 {25 throw new Win32Exception();26 }27 }28 /// <summary>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 RECT220 {221 left = touchPoint.X,222 right = touchPoint.X,223 top = touchPoint.Y,224 bottom = touchPoint.Y225 }226 };227 return contact;228 }229 /// <summary>230 /// Effectively executes the touch input action.231 /// </summary>232 /// <param name="contacts">The list of input contacts which should be executed.</param>233 private static void InjectTouchInput(POINTER_TOUCH_INFO[] contacts)234 {235 if (contacts == null)236 {237 throw new ArgumentNullException(nameof(contacts));238 }239 if (!User32.InjectTouchInput(contacts.Length, contacts))240 {241 throw new Win32Exception();242 }243 }244 }245}...

Full Screen

Full Screen

TouchTests.cs

Source:TouchTests.cs Github

copy

Full Screen

...5namespace FlaUI.Core.UITests6{7 [TestFixture]8 [Ignore("Only for local testing for now as a demo app is missing.")]9 public class TouchTests10 {11 [Test]12 public void Test()13 {14 var currPos = Mouse.Position;15 Touch.Tap(currPos);16 Touch.Hold(TimeSpan.FromSeconds(2), currPos);17 Touch.Pinch(currPos, 0, 100, TimeSpan.FromSeconds(2));18 Touch.Drag(TimeSpan.FromSeconds(2), currPos, Point.Add(currPos, new Size(100, 0)));19 Touch.Rotate(currPos, 200, 0, 2 * Math.PI, TimeSpan.FromSeconds(3));20 }21 }22}...

Full Screen

Full Screen

Touch

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using FlaUI.Core;7using FlaUI.Core.AutomationElements;8using FlaUI.Core.Definitions;9using FlaUI.Core.Input;10using FlaUI.Core.WindowsAPI;11using FlaUI.UIA3;12{13 {14 static void Main(string[] args)15 {16 var app = FlaUI.Core.Application.Launch(@"C:\Windows\System32\notepad.exe");17 var window = app.GetMainWindow(new UIA3Automation());18 var textBox = window.FindFirstDescendant(cf => cf.ByAutomationId("15"));19 textBox.Enter("Hello World");20 var button = window.FindFirstDescendant(cf => cf.ByAutomationId("1"));21 button.Click();22 app.Close();23 app.Dispose();24 System.Threading.Thread.Sleep(5000);25 }26 }27}28CS0246: The type or namespace name ‘Touch’ could not be found (are you missing a using directive or an assembly referen

Full Screen

Full Screen

Touch

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.Input;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 var app = FlaUI.Core.Application.Launch("C:\\Windows\\System32\\notepad.exe");12 var desktop = FlaUI.Core.Desktop.Instance;13 var window = desktop.Windows().FirstOrDefault(w => w.Title.Contains("Untitled - Notepad"));14 var touch = new Touch();15 touch.Move(window, 100, 100);16 touch.Press();17 touch.Move(window, 200, 200);18 touch.Release();19 }20 }21}22using FlaUI.Core.Input;23using FlaUI.UIA3;24using System;25using System.Collections.Generic;26using System.Linq;27using System.Text;28using System.Threading.Tasks;29{30 {31 static void Main(string[] args)32 {33 var app = FlaUI.Core.Application.Launch("C:\\Windows\\System32\\notepad.exe");34 var desktop = FlaUI.Core.Desktop.Instance;35 var window = desktop.Windows().FirstOrDefault(w => w.Title.Contains("Untitled - Notepad"));36 var touch = new Touch();37 touch.Move(window, 100, 100);38 touch.Press();39 touch.Move(window, 200, 200);40 touch.Release();41 }42 }43}44using FlaUI.Core.Input;45using FlaUI.UIA2;46using System;47using System.Collections.Generic;48using System.Linq;49using System.Text;50using System.Threading.Tasks;51{52 {53 static void Main(string[] args)54 {55 var app = FlaUI.Core.Application.Launch("C:\\Windows\\System32\\notepad.exe");56 var desktop = FlaUI.Core.Desktop.Instance;57 var window = desktop.Windows().FirstOrDefault(w => w.Title.Contains("Untitled - Notepad"));58 var touch = new Touch();59 touch.Move(window, 100, 100);60 touch.Press();61 touch.Move(window, 200, 200);62 touch.Release();

Full Screen

Full Screen

Touch

Using AI Code Generation

copy

Full Screen

1using FlaUI.UIA3.Input;2{3 {4 static void Main(string[] args)5 {6 var application = FlaUI.Core.Application.Launch(@"C:\Windows\System32\calc.exe");7 var window = application.GetMainWindow(FlaUI.Core.Conditions.ConditionFactory.ByAutomationId("CalculatorFrame"));8 var button = window.FindFirstDescendant(FlaUI.Core.Conditions.ConditionFactory.ByAutomationId("num8Button"));9 var button2 = window.FindFirstDescendant(FlaUI.Core.Conditions.ConditionFactory.ByAutomationId("num9Button"));10 button.Click();11 button2.Click();12 button.Click();13 button2.Click();14 button.Click();

Full Screen

Full Screen

Touch

Using AI Code Generation

copy

Full Screen

1Touch.Tap(100, 100);2Touch.Tap(100, 100);3Touch.Tap(100, 100);4Touch.Tap(100, 100);5Touch.Tap(100, 100);6Touch.Tap(100, 100);7Touch.Tap(100, 100);8Touch.Tap(100, 100);9Touch.Tap(100, 100);10Touch.Tap(100, 100);11Touch.Tap(100, 100);12Touch.Tap(100, 100);13Touch.Tap(100, 100);14Touch.Tap(100, 100);15Touch.Tap(100, 100);16Touch.Tap(100, 100);17Touch.Tap(100, 100);18Touch.Tap(100

Full Screen

Full Screen

Touch

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.Input;2using System.Windows.Forms;3using FlaUI.Core.AutomationElements;4using FlaUI.Core;5using FlaUI.Core.AutomationElements.Infrastructure;6using FlaUI.Core.Definitions;7using FlaUI.Core.WindowsAPI;8using System;9using System.Collections.Generic;10using System.Linq;11using System.Text;12using System.Threading.Tasks;13using System.Diagnostics;14using FlaUI.Core.WindowsAPI;15{16 {17 public static void Tap(AutomationElement element, int x = 0, int y = 0)18 {19 var rect = element.BoundingRectangle;20 var point = new System.Drawing.Point((int)rect.Left + x, (int)rect.Top + y);21 {22 };23 {24 {25 {26 dx = (int)(point.X * (65535.0 / System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width)),27 dy = (int)(point.Y * (65535.0 / System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height))28 }29 }30 };31 var inputs = new NativeMethods.INPUT[2];32 inputs[0] = input;33 inputs[1].type = NativeMethods.INPUT_TOUCH;34 inputs[1].u = new NativeMethods.INPUTUNION();35 inputs[1].u.ti = touchInput;36 var result = NativeMethods.SendInput(2, inputs, Marshal.SizeOf(typeof(NativeMethods.INPUT)));37 if (result == 0)38 {39 throw new Exception("Could not send touch input");40 }41 }42 }43}44using FlaUI.Core;45using FlaUI.Core.AutomationElements;

Full Screen

Full Screen

Touch

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.Input;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7using System.Windows.Forms;8{9 {10 public static void Main()11 {12 Touch touch = new Touch();13 touch.Down(100, 100);14 touch.Move(200, 200);15 touch.Up(200, 200);16 }17 }18}19using FlaUI.Core.Input;20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using System.Threading.Tasks;25using System.Windows.Forms;26using FlaUI.Core.AutomationElements;27{28 {29 public static void Main()30 {31 Touch touch = new Touch();32 touch.Down(100, 100);33 touch.Move(200, 200);34 touch.Up(200, 200);35 }36 }37}38using FlaUI.Core.Input;39using System;40using System.Collections.Generic;41using System.Linq;42using System.Text;43using System.Threading.Tasks;44using System.Windows.Forms;45using FlaUI.Core.AutomationElements;46using FlaUI.Core;47using FlaUI.UIA3;48using FlaUI.Core.Definitions;49{50 {

Full Screen

Full Screen

Touch

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.Input;2using FlaUI.Core.WindowsAPI;3using FlaUI.UIA3;4using System;5using System.Diagnostics;6using System.Threading;7using System.Windows.Forms;8using static FlaUI.Core.Input.Keyboard;9{10 {11 static void Main(string[] args)12 {13 Process process = Process.Start(@"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE");14 Thread.Sleep(2000);15 var automation = new UIA3Automation();16 var window = automation.GetDesktop().FindFirstDescendant(cf => cf.ByProcessId(process.Id)).AsWindow();17 var button = window.FindFirstDescendant(cf => cf.ByName("New")).AsButton();18 button.Click();19 var cell = window.FindFirstDescendant(cf => cf.ByAutomationId("CellRangeControl")).AsTextBox();20 cell.Click();21 cell.Send("Hello World");22 Console.ReadLine();23 process.CloseMainWindow();24 }25 }26}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run FlaUI automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful