How to use InjectTouchInput method of FlaUI.Core.Input.Touch class

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

Touch.cs

Source:Touch.cs Github

copy

Full Screen

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

User32.cs

Source:User32.cs Github

copy

Full Screen

...77 public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);78 [DllImport("User32.dll", SetLastError = true)]79 public static extern bool InitializeTouchInjection(uint maxCount = 256, InjectedInputVisualizationMode feedbackMode = InjectedInputVisualizationMode.DEFAULT);80 [DllImport("User32.dll", SetLastError = true)]81 public static extern bool InjectTouchInput(int count, [MarshalAs(UnmanagedType.LPArray), In] POINTER_TOUCH_INFO[] contacts);82 [DllImport("kernel32.dll", SetLastError = true)]83 public static extern IntPtr OpenProcess(ProcessAccessFlags processAccess, bool bInheritHandle, int processId);84 [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]85 public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect);86 [DllImport("kernel32.dll", SetLastError = true)]87 public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);88 [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]89 public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, AllocationType dwFreeType);90 [DllImport("kernel32.dll", SetLastError = true)]91 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]92 [SuppressUnmanagedCodeSecurity]93 [return: MarshalAs(UnmanagedType.Bool)]94 public static extern bool CloseHandle(IntPtr hObject);95 [DllImport("kernel32.dll", SetLastError = true)]...

Full Screen

Full Screen

InjectTouchInput

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.Input;8{9 {10 static void Main(string[] args)11 {12 var app = FlaUI.Core.Application.Launch("notepad.exe");13 var window = app.GetMainWindow(FlaUI.Core.Automation.TreeScope.Descendants, TimeSpan.FromMinutes(1));14 window.SetForeground();15 var input = new FlaUI.Core.Input.Touch();16 input.InjectTouchInput(0, 0, 0, 0, 0);17 System.Threading.Thread.Sleep(5000);18 input.InjectTouchInput(0, 0, 0, 0, 0);19 }20 }21}22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using FlaUI.Core;28using FlaUI.Core.Input;29{30 {31 static void Main(string[] args)32 {33 var app = FlaUI.Core.Application.Launch("notepad.exe");34 var window = app.GetMainWindow(FlaUI.Core.Automation.TreeScope.Descendants, TimeSpan.FromMinutes(1));35 window.SetForeground();36 var input = new FlaUI.Core.Input.Touch();37 input.InjectTouchInput(0, 0, 0, 0, 0);38 System.Threading.Thread.Sleep(5000);39 input.InjectTouchInput(0, 0, 0, 0, 0);40 }41 }42}43using System;44using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48using FlaUI.Core;49using FlaUI.Core.Input;50{51 {52 static void Main(string[] args)53 {54 var app = FlaUI.Core.Application.Launch("notepad.exe");55 var window = app.GetMainWindow(FlaUI.Core.Automation.TreeScope.Descendants, TimeSpan.FromMinutes(1));56 window.SetForeground();57 var input = new FlaUI.Core.Input.Touch();58 input.InjectTouchInput(0, 0, 0, 0, 0);

Full Screen

Full Screen

InjectTouchInput

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.Input;7{8 {9 static void Main(string[] args)10 {11 Touch.InjectTouchInput(1, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);12 }13 }14}154) Please check the FlaUI.Core.Input.Touch.InjectTouchInput() method is called after

Full Screen

Full Screen

InjectTouchInput

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.Input;8using FlaUI.Core.WindowsAPI;9using FlaUI.UIA3;10{11 {12 static void Main(string[] args)13 {14 var application = FlaUI.Core.Application.Launch(@"C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_10.1908.24.0_x64__8wekyb3d8bbwe\Calculator.exe");15 var automation = new UIA3Automation();16 var window = application.GetMainWindow(automation);17 Touch.InjectTouchInput(0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);18 application.Close();19 }20 }21}22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using FlaUI.Core;28using FlaUI.Core.Input;29using FlaUI.Core.WindowsAPI;30using FlaUI.UIA3;31{32 {33 static void Main(string[] args)34 {35 var application = FlaUI.Core.Application.Launch(@"C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_10.1908.24.0_x64__8wekyb3d8bbwe\Calculator.exe");36 var automation = new UIA3Automation();37 var window = application.GetMainWindow(automation);38 Touch.InjectTouchInput(0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);39 application.Close();40 }41 }42}43using System;44using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48using FlaUI.Core;49using FlaUI.Core.Input;50using FlaUI.Core.WindowsAPI;

Full Screen

Full Screen

InjectTouchInput

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.Input;7using FlaUI.Core.WindowsAPI;8{9 {10 public static void InjectTouchInput(List<TouchInput> touchInputs)11 {12 if (touchInputs.Count > 0)13 {14 var touchInput = new TouchInput[touchInputs.Count];15 for (int i = 0; i < touchInputs.Count; i++)16 {17 touchInput[i] = touchInputs[i].ToTouchInput();18 }19 User32Wrapper.InjectTouchInput((uint)touchInputs.Count, touchInput);20 }21 }22 }23}24using System;25using System.Collections.Generic;26using System.Linq;27using System.Text;28using System.Threading.Tasks;29using FlaUI.Core.Input;30using FlaUI.Core.WindowsAPI;31{32 {33 public TouchInput(int x, int y, int id, TouchInputFlags flags)34 {35 X = x;36 Y = y;37 Id = id;38 Flags = flags;39 Mask = TouchInputMask.X | TouchInputMask.Y | TouchInputMask.ContactArea | TouchInputMask.Orientation | TouchInputMask.Pressure;40 Time = 0;41 ContactArea = new RawInputRectangle();42 Orientation = 0;43 Pressure = 0;44 }45 public int X { get; set; }46 public int Y { get; set; }47 public int Id { get; set; }48 public TouchInputFlags Flags { get; set; }49 public TouchInputMask Mask { get; set; }50 public int Time { get; set; }51 public RawInputRectangle ContactArea { get; set; }52 public int Orientation { get; set; }53 public int Pressure { get; set; }54 public TouchInput ToTouchInput()55 {56 {57 };58 return touchInput;59 }60 }61}

Full Screen

Full Screen

InjectTouchInput

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.Input;8using FlaUI.Core.WindowsAPI;9using System.Windows.Forms;10using System.Drawing;11using System.Threading;12{13 {14 static void Main(string[] args)15 {16 var app = Application.Launch(@"C:\Windows\System32\calc.exe");17 app.WaitWhileBusy();18 var mainWindow = app.GetMainWindow();19 var button = mainWindow.FindFirstChild(cf => cf.ByAutomationId("num7Button")).AsButton();20 var buttonBounds = button.BoundingRectangle;21 var point = new Point((int)buttonBounds.Left + 10, (int)buttonBounds.Top + 10);22 Touch.InjectTouchInput(point, TouchInputType.Down);23 Thread.Sleep(1000);24 Touch.InjectTouchInput(point, TouchInputType.Up);25 app.Close();26 }27 }28}

Full Screen

Full Screen

InjectTouchInput

Using AI Code Generation

copy

Full Screen

1using System;2using FlaUI.Core;3using FlaUI.Core.Input;4using FlaUI.Core.WindowsAPI;5{6 {7 static void Main(string[] args)8 {9 var automation = AutomationUtil.GetAutomation();10 var window = automation.GetDesktop().FindFirstChild(cf => cf.ByControlType(ControlType.Window).And(cf.ByName("Calculator")));11 window.Focus();12 var inputSimulator = new InputSimulator();13 inputSimulator.Touch.InjectTouchInput(TouchInputType.Down, 100, 100, 0);14 inputSimulator.Touch.InjectTouchInput(TouchInputType.Up, 100, 100, 0);15 }16 }17}18using System;19using FlaUI.Core;20using FlaUI.Core.Input;21using FlaUI.Core.WindowsAPI;22{23 {24 static void Main(string[] args)25 {26 var automation = AutomationUtil.GetAutomation();27 var window = automation.GetDesktop().FindFirstChild(cf => cf.ByControlType(ControlType.Window).And(cf.ByName("Calculator")));28 window.Focus();29 var inputSimulator = new InputSimulator();30 inputSimulator.Touch.InjectTouchInput(TouchInputType.Down, 100, 100, 0);31 inputSimulator.Touch.InjectTouchInput(TouchInputType.Move, 200, 200, 0);32 inputSimulator.Touch.InjectTouchInput(TouchInputType.Up, 200, 200, 0);33 }34 }35}36using System;37using FlaUI.Core;38using FlaUI.Core.Input;39using FlaUI.Core.WindowsAPI;40{41 {42 static void Main(string[] args)43 {44 var automation = AutomationUtil.GetAutomation();45 var window = automation.GetDesktop().FindFirstChild(cf => cf.ByControlType(ControlType.Window).And(cf.ByName("Calculator")));46 window.Focus();47 var inputSimulator = new InputSimulator();48 inputSimulator.Touch.InjectTouchInput(TouchInputType.Down, 100, 100, 0);49 inputSimulator.Touch.InjectTouchInput(TouchInputType.Move, 200, 200, 0);

Full Screen

Full Screen

InjectTouchInput

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.Input;2using FlaUI.Core.WindowsAPI;3using System;4using System.Collections.Generic;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8{9 {10 public static void InjectTouchInput()11 {12 {13 };14 FlaUI.Core.Input.Touch.InjectTouchInput(new[] { touchInput });15 }16 }17}18using FlaUI.Core.Input;19using FlaUI.Core.WindowsAPI;20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using System.Threading.Tasks;25{26 {27 public static void SendKey()28 {29 FlaUI.Core.Input.Keyboard.SendKey(System.Windows.Forms.Keys.A);30 }31 }32}33using FlaUI.Core.Input;34using FlaUI.Core.WindowsAPI;35using System;36using System.Collections.Generic;37using System.Linq;38using System.Text;39using System.Threading.Tasks;40{41 {42 public static void SendText()43 {44 FlaUI.Core.Input.Keyboard.SendText("Hello World");45 }46 }47}48using FlaUI.Core.Input;49using FlaUI.Core.WindowsAPI;50using System;51using System.Collections.Generic;52using System.Linq;53using System.Text;54using System.Threading.Tasks;55{56 {57 public static void SendKeyDown()58 {59 FlaUI.Core.Input.Keyboard.SendKeyDown(System.Windows.Forms.Keys.A);60 }61 }62}

Full Screen

Full Screen

InjectTouchInput

Using AI Code Generation

copy

Full Screen

1using System;2using FlaUI.Core;3using FlaUI.Core.Input;4using FlaUI.Core.WindowsAPI;5{6 {7 static void Main(string[] args)8 {9 var app = FlaUI.Core.Application.Launch(@"C:\Program Files (x86)\Windows Media Player\wmplayer.exe");10 var window = app.GetMainWindow(FlaUI.Core.Conditions.ConditionFactory.ByClassName("WindowsMediaPlayerApp"));11 var touch = new FlaUI.Core.Input.Touch();12 touch.InjectTouchInput(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);13 touch.InjectTouchInput(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);14 touch.InjectTouchInput(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);15 touch.InjectTouchInput(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);16 touch.InjectTouchInput(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);17 touch.InjectTouchInput(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);18 touch.InjectTouchInput(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);19 touch.InjectTouchInput(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);20 }21 }22}23using System;24using FlaUI.Core;25using FlaUI.Core.Input;

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