aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SimulateTouch.UI/TouchController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.SimulateTouch.UI/TouchController.cs')
-rw-r--r--Software/Visual_Studio/Tango.SimulateTouch.UI/TouchController.cs81
1 files changed, 81 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.SimulateTouch.UI/TouchController.cs b/Software/Visual_Studio/Tango.SimulateTouch.UI/TouchController.cs
new file mode 100644
index 000000000..144047b0c
--- /dev/null
+++ b/Software/Visual_Studio/Tango.SimulateTouch.UI/TouchController.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.SimulateTouch.UI.Native;
+
+namespace Tango.SimulateTouch.UI
+{
+ public static class TouchController
+ {
+ private static bool _initialized;
+ private static PointerTouchInfo? _currentContact;
+
+ public static void Init()
+ {
+ if (!_initialized)
+ {
+ _initialized = true;
+ TouchInjector.InitializeTouchInjection();
+ }
+ }
+
+ public static void TouchDown(int x, int y)
+ {
+ Init();
+
+ var contact = MakePointerTouchInfo(x, y, 1);
+ PointerFlags oFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
+ contact.PointerInfo.PointerFlags = oFlags;
+ bool bIsSuccess = TouchInjector.InjectTouchInput(1, new[] { contact });
+ _currentContact = contact;
+ }
+
+ public static void TouchUp()
+ {
+ Init();
+
+ if (_currentContact != null)
+ {
+ var contact = _currentContact.Value;
+ contact.PointerInfo.PointerFlags = PointerFlags.UP;
+ TouchInjector.InjectTouchInput(1, new[] { contact });
+ _currentContact = null;
+ }
+ }
+
+ public static void TouchMove(int deltaX, int deltaY)
+ {
+ Init();
+
+ if (_currentContact != null)
+ {
+ var contact = _currentContact.Value;
+ contact.Move(deltaX, deltaY);
+ var oFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.UPDATE;
+ contact.PointerInfo.PointerFlags = oFlags;
+ TouchInjector.InjectTouchInput(1, new[] { contact });
+ }
+ }
+
+ private static PointerTouchInfo MakePointerTouchInfo(int x, int y, int radius, uint orientation = 90, uint pressure = 32000)
+ {
+ PointerTouchInfo contact = new PointerTouchInfo();
+ contact.PointerInfo.pointerType = PointerInputType.TOUCH;
+ contact.TouchFlags = TouchFlags.NONE;
+ contact.Orientation = orientation;
+ contact.Pressure = pressure;
+ contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
+ contact.PointerInfo.PtPixelLocation.X = x;
+ contact.PointerInfo.PtPixelLocation.Y = y;
+ uint unPointerId = IdGenerator.GetUinqueUInt();
+ contact.PointerInfo.PointerId = unPointerId;
+ contact.ContactArea.left = x - radius;
+ contact.ContactArea.right = x + radius;
+ contact.ContactArea.top = y - radius;
+ contact.ContactArea.bottom = y + radius;
+ return contact;
+ }
+ }
+}