How to use InjectTouchInput method of FlaUI.Core.WindowsAPI.User32 class

Best FlaUI code snippet using FlaUI.Core.WindowsAPI.User32.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 FlaUI.Core.WindowsAPI;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7using System.Windows.Forms;8{9 {10 static void Main(string[] args)11 {12 IntPtr handle = User32.FindWindow(null, "Notepad");13 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);14 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);15 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);16 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);17 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);18 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);19 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);20 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0);21 User32.InjectTouchInput(handle, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0

Full Screen

Full Screen

InjectTouchInput

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.WindowsAPI;2using System;3using System.Windows.Forms;4{5 {6 public Form1()7 {8 InitializeComponent();9 }10 private void button1_Click(object sender, EventArgs e)11 {12 User32.InjectTouchInput(1, new User32.POINTER_TOUCH_INFO[] { new User32.POINTER_TOUCH_INFO() { pointerInfo = new User32.POINTER_INFO() { pointerType = User32.POINTER_INPUT_TYPE.TOUCH, pointerId = 0, ptPixelLocation = new User32.POINT() { x = 100, y = 100 }, pointerFlags = User32.POINTER_FLAGS.DOWN | User32.POINTER_FLAGS.INRANGE | User32.POINTER_FLAGS.INCONTACT } } }, (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(User32.POINTER_TOUCH_INFO)));13 }14 }15}16using FlaUI.Core.WindowsAPI;17using System;18using System.Windows.Forms;19{20 {21 public Form1()22 {23 InitializeComponent();24 }25 private void button1_Click(object sender, EventArgs e)26 {27 User32.InjectMouseInput(User32.MOUSEEVENTF.LEFTDOWN, 100, 100, 0, 0);28 }29 }30}31using FlaUI.Core.WindowsAPI;32using System;33using System.Windows.Forms;34{35 {36 public Form1()37 {38 InitializeComponent();39 }40 private void button1_Click(object

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.WindowsAPI;7using System.Runtime.InteropServices;8{9 {10 static void Main(string[] args)11 {12 User32.TOUCHINPUT ti = new User32.TOUCHINPUT();13 ti.x = 100;14 ti.y = 100;15 ti.dwFlags = User32.TOUCHINPUTMASK.TOUCHINPUTMASKF_DOWN | User32.TOUCHINPUTMASK.TOUCHINPUTMASKF_UP;16 ti.dwID = 0;17 ti.dwTime = 0;18 ti.dwExtraInfo = IntPtr.Zero;19 ti.cxContact = 1;20 ti.cyContact = 1;21 ti.dwMask = User32.TOUCHINPUTMASK.TOUCHINPUTMASKF_ALL;22 User32.TOUCHINPUT[] tiArray = new User32.TOUCHINPUT[1];23 tiArray[0] = ti;24 IntPtr hTouchInput = Marshal.AllocHGlobal(Marshal.SizeOf(tiArray[0]) * tiArray.Length);25 Marshal.StructureToPtr(tiArray[0], hTouchInput, false);26 IntPtr pTouchInput = hTouchInput;27 IntPtr[] pInputs = new IntPtr[1];28 pInputs[0] = pTouchInput;29 IntPtr pInputsPointer = Marshal.UnsafeAddrOfPinnedArrayElement(pInputs, 0);30 User32.InjectTouchInput(1, pInputsPointer, Marshal.SizeOf(ti));31 }32 }33}

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.WindowsAPI;7using FlaUI.Core.WindowsAPI;8{9 {10 public static void InjectTouchInput(TOUCHINPUT[] inputs)11 {12 if (inputs == null || inputs.Length == 0)13 {14 return;15 }16 var sizeOfTouchInput = Marshal.SizeOf(inputs[0]);17 var sizeOfTouchInputArray = sizeOfTouchInput * inputs.Length;18 var touchInputArrayPtr = Marshal.AllocHGlobal(sizeOfTouchInputArray);19 var touchInputArray = new byte[sizeOfTouchInputArray];20 for (var i = 0; i < inputs.Length; i++)21 {22 var touchInputPtr = new IntPtr(touchInputArrayPtr.ToInt64() + i * sizeOfTouchInput);23 Marshal.StructureToPtr(inputs[i], touchInputPtr, false);24 Marshal.Copy(touchInputPtr, touchInputArray, i * sizeOfTouchInput, sizeOfTouchInput);25 }26 var ret = InjectTouchInput(inputs.Length, touchInputArrayPtr, sizeOfTouchInput);27 if (ret == 0)28 {29 throw new Win32Exception("InjectTouchInput failed");30 }31 Marshal.FreeHGlobal(touchInputArrayPtr);32 }33 }34}35using FlaUI.Core.WindowsAPI;36using FlaUI.Core.WindowsAPI;37using System;38using System.Collections.Generic;39using System.Linq;40using System.Text;41using System.Threading.Tasks;42{43 {44 public static void InjectTouchInput(TOUCHINPUT[] inputs)45 {46 if (inputs == null || inputs.Length == 0)47 {48 return;49 }50 var sizeOfTouchInput = Marshal.SizeOf(inputs[0]);51 var sizeOfTouchInputArray = sizeOfTouchInput * inputs.Length;52 var touchInputArrayPtr = Marshal.AllocHGlobal(sizeOfTouchInputArray);53 var touchInputArray = new byte[sizeOfTouchInputArray];54 for (var i = 0; i < inputs.Length; i++)55 {56 var touchInputPtr = new IntPtr(touchInputArrayPtr.ToInt64() + i * sizeOfTouchInput

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;6{7 {8 [DllImport("User32.dll", SetLastError = true)]9 public static extern int InjectTouchInput(int count, [In] TouchInput[] inputs);10 public static int InjectTouchInput(TouchInput[] inputs)11 {12 return InjectTouchInput(inputs.Length, inputs);13 }14 }15}16using System;17using System.Collections.Generic;18using System.Linq;19using System.Text;20using System.Threading.Tasks;21{22 [StructLayout(LayoutKind.Sequential)]23 {24 public int x;25 public int y;26 public IntPtr hSource;27 public int dwID;28 public int dwFlags;29 public int dwMask;30 public int dwTime;31 public IntPtr dwExtraInfo;32 public int cxContact;33 public int cyContact;34 }35}36using System;37using System.Collections.Generic;38using System.Linq;39using System.Text;40using System.Threading.Tasks;41{42 {43 }44}45using System;46using System.Collections.Generic;47using System.Linq;48using System.Text;49using System.Threading.Tasks;50{51 {

Full Screen

Full Screen

InjectTouchInput

Using AI Code Generation

copy

Full Screen

1using System;2using System.Windows.Forms;3using System.Drawing;4using System.Threading;5using FlaUI.Core.WindowsAPI;6{7 {8 public static void InjectTouchInput(int numberOfInputs, TouchInput[] inputs, int sizeOfTouchInputStructure)9 {10 User32.InjectTouchInput(numberOfInputs, inputs, sizeOfTouchInputStructure);11 }12 }13}14{15 {16 public int x;17 public int y;18 public IntPtr hSource;19 public int dwID;20 public int dwFlags;21 public int dwMask;22 public int dwTime;23 public IntPtr dwExtraInfo;24 public int cxContact;25 public int cyContact;26 }27}28{29 {30 }31}32{33 {34 }35}36{37 {

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.WindowsAPI;8using FlaUI.Core.WindowsAPI.Enums;9using FlaUI.Core.WindowsAPI.Structs;10using FlaUI.Core.WindowsAPI.User32;11using FlaUI.UIA2;12using FlaUI.UIA3;13using FlaUI.UIA3.Patterns;14using FlaUI.Core.Definitions;15using FlaUI.Core.AutomationElements.Infrastructure;16using FlaUI.Core.Conditions;17using FlaUI.Core.Input;18using FlaUI.Core.AutomationElements;19using FlaUI.Core.AutomationElements.PatternElements;20using FlaUI.Core.Patterns;21using FlaUI.Core.Tools;22using FlaUI.Core.WindowsAPI;23using FlaUI.Core.WindowsAPI.Enums;24using FlaUI.Core.WindowsAPI.Structs;25using FlaUI.Core.WindowsAPI.User32;26using System.Drawing;27using System.Windows.Forms;28using System.Threading;29using FlaUI.Core.WindowsAPI.Structs;30{31 {32 static void Main(string[] args)33 {34 var app = FlaUI.Core.Application.Launch("C:\\Windows\\System32\\notepad.exe");35 var mainWindow = app.GetMainWindow();36 var button = mainWindow.FindFirstDescendant(cf => cf.ByAutomationId("1"));37 var result = mainWindow.FindFirstDescendant(cf => cf.ByAutomationId("5000"));38 InjectTouchInput(button);39 if (result.Text == "OK")40 {41 Console.WriteLine("The 'Ok' button is

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful