aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.SimulateTouch.UI/MainWindow.xaml.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-06-07 09:50:29 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-06-07 09:50:29 +0300
commit714c2fd7941c3f65e363a3d9cc33765c746f0c59 (patch)
treed936bc5a7c64b5a3227a41ae742142fbb835bca8 /Software/Visual_Studio/Tango.SimulateTouch.UI/MainWindow.xaml.cs
parent8f02bc33eab3c82aac624c390c0805bf29816108 (diff)
downloadTango-714c2fd7941c3f65e363a3d9cc33765c746f0c59.tar.gz
Tango-714c2fd7941c3f65e363a3d9cc33765c746f0c59.zip
Refined touch simulation test.
Diffstat (limited to 'Software/Visual_Studio/Tango.SimulateTouch.UI/MainWindow.xaml.cs')
-rw-r--r--Software/Visual_Studio/Tango.SimulateTouch.UI/MainWindow.xaml.cs149
1 files changed, 48 insertions, 101 deletions
diff --git a/Software/Visual_Studio/Tango.SimulateTouch.UI/MainWindow.xaml.cs b/Software/Visual_Studio/Tango.SimulateTouch.UI/MainWindow.xaml.cs
index 33181b13d..27f316bb3 100644
--- a/Software/Visual_Studio/Tango.SimulateTouch.UI/MainWindow.xaml.cs
+++ b/Software/Visual_Studio/Tango.SimulateTouch.UI/MainWindow.xaml.cs
@@ -15,6 +15,7 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.SimulateTouch.UI.Native;
using System.Security.Cryptography;
+using System.Threading;
namespace Tango.SimulateTouch.UI
{
@@ -23,129 +24,75 @@ namespace Tango.SimulateTouch.UI
/// </summary>
public partial class MainWindow : Window
{
- //Windows.UI.Input.Preview.Injection.InputInjector _inputInjector;
- private Line ProxyLine;
+ private Point downPosition;
public MainWindow()
{
InitializeComponent();
- WindowState = WindowState.Maximized;
- TouchInjector.InitializeTouchInjection();
- this.TouchDown += MainWindow_TouchDown;
- this.TouchMove += MainWindow_TouchMove;
- this.TouchUp += MainWindow_TouchUp;
+
+ TouchController.Init();
+
+ rect.TouchDown += Rect_TouchDown;
+ rect.TouchUp += Rect_TouchUp;
+ rect.TouchMove += Rect_TouchMove;
}
- private void MainWindow_TouchUp(object sender, TouchEventArgs e)
+
+ private void Rect_TouchDown(object sender, TouchEventArgs e)
{
- System.Windows.Input.TouchPoint oPos = e.GetTouchPoint(this);
- this.ProxyLine.X2 = oPos.Position.X;
- this.ProxyLine.Y2 = oPos.Position.Y;
- this.GdRootZm.Children.Add(this.ProxyLine);
- Console.WriteLine("TouchID " + e.TouchDevice.Id + " TouchUp " + oPos.Position.X + " " + oPos.Position.Y);
- TouchUpTextBlock.Text = "TOUCH UP";
+ downPosition = e.GetTouchPoint(rect).Position;
+ rect.Fill = Brushes.Blue;
}
- private void MainWindow_TouchMove(object sender, TouchEventArgs e)
+ private void Rect_TouchUp(object sender, TouchEventArgs e)
{
- System.Windows.Input.TouchPoint oPos = e.GetTouchPoint(this);
- Console.WriteLine("TouchID " + e.TouchDevice.Id + " TouchMove " + oPos.Position.X + " " + oPos.Position.Y);
+ rect.Fill = Brushes.Red;
}
- private void MainWindow_TouchDown(object sender, TouchEventArgs e)
+ private void Rect_TouchMove(object sender, TouchEventArgs e)
{
- System.Windows.Input.TouchPoint oPos = e.GetTouchPoint(this);
- Line oLine = new Line();
- oLine.Stroke = new SolidColorBrush(Colors.Red);
- oLine.StrokeThickness = 2;
- oLine.X1 = oPos.Position.X;
- oLine.Y1 = oPos.Position.Y;
- this.ProxyLine = oLine;
- Console.WriteLine("TouchID " + e.TouchDevice.Id + " TouchDown " + oPos.Position.X + " " + oPos.Position.Y);
- messageTextBlock.Text = "TOUCH Down";
+ var position = e.GetTouchPoint(rect).Position;
+
+ Canvas.SetLeft(rect, (Canvas.GetLeft(rect) + position.X) - downPosition.X);
+ Canvas.SetTop(rect, (Canvas.GetTop(rect) + position.Y) - downPosition.Y);
}
-
- private void OnButtonLeftButtonDown(object sender, MouseButtonEventArgs e)
+
+ private void BtnStart_Click(object sender, RoutedEventArgs e)
{
- // Point targetLoc = messageTextBlock.PointToScreen(new Point(0, 0));
- // HwndSource source = (HwndSource)HwndSource.FromVisual(messageTextBlock);
- // IntPtr hWnd = source.Handle;
- Console.WriteLine("OnButtonLeftButtonDown");
+ Point rectPosition = rect.PointToScreen(new Point(0, 0));
+ Size rectSize = new Size(rect.ActualWidth, rect.ActualHeight);
- TouchSimulate ts = new TouchSimulate();
+ Point lastDelta = new Point(0, 0);
+ bool completed = false;
- //TEST UWP - error COM!!!!
- /* _inputInjector = InputInjector.TryCreate();
- if (_inputInjector != null)
- {
- _inputInjector.InitializeTouchInjection( InjectedInputVisualizationMode.Default);
- uint pointerId = 1;
- var appBounds = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds;
- Point appBoundsTopLeft = new Point(appBounds.Left, appBounds.Top);
- Point targetLoc = messageTextBlock.PointToScreen(new Point(0, 0));
+ Thread t = new Thread(() =>
+ {
+ TouchController.TouchDown((int)(rectPosition.X + rectSize.Width / 2), (int)(rectPosition.Y + rectSize.Height / 2)); //Touch the middle of the red rectangle.
- // Get the screen coordinates (relative to the input area)
- // of the input pointer.
- Point screenPointPosition = button.PointToScreen(coordinates);
- int pointerPointX = (int)screenPointPosition.X;
- int pointerPointY = (int)screenPointPosition.Y;
+ Task.Factory.StartNew(() => //This is necessary to keep the touch session alive.
+ {
+ while (!completed)
+ {
+ TouchController.TouchMove((int)lastDelta.X, (int)lastDelta.Y);
+ Thread.Sleep(100);
+ }
+ });
- // Create the point for input injection and calculate its screen location.
- Point injectionPoint =
- new Point(
- appBoundsTopLeft.X + targetLoc.X + pointerPointX,
- appBoundsTopLeft.Y + targetLoc.Y + pointerPointY);
+ Thread.Sleep(1000);
- // Create a touch data point for pointer down.
- // Each element in the touch data list represents a single touch contact.
- // For this example, we're mirroring a single mouse pointer.
- List<InjectedInputTouchInfo> touchData = new List<InjectedInputTouchInfo>
- {
- new InjectedInputTouchInfo
- {
- Contact = new InjectedInputRectangle
- {
- Left = 30, Top = 30, Bottom = 30, Right = 30
- },
- PointerInfo = new InjectedInputPointerInfo
- {
- PointerId = pointerId,
- PointerOptions =
- InjectedInputPointerOptions.PointerDown |
- InjectedInputPointerOptions.InContact |
- InjectedInputPointerOptions.New,
- TimeOffsetInMilliseconds = 0,
- PixelLocation = new InjectedInputPoint
- {
- PositionX = (int)injectionPoint.X ,
- PositionY = (int)injectionPoint.Y
- }
- },
- Pressure = 1.0,
- TouchParameters =
- InjectedInputTouchParameters.Pressure |
- InjectedInputTouchParameters.Contact
- }
- };
+ for (int i = 0; i < 51; i++) //Animate movement.
+ {
+ TouchController.TouchMove(i, i);
+ lastDelta = new Point(i, i);
+ Thread.Sleep(300);
+ }
- // Inject the touch input.
- _inputInjector.InjectTouchInput(touchData);
+ completed = true;
- // Create a touch data point for pointer up.
- touchData = new List<InjectedInputTouchInfo>
- {
- new InjectedInputTouchInfo
- {
- PointerInfo = new InjectedInputPointerInfo
- {
- PointerId = pointerId,
- PointerOptions = InjectedInputPointerOptions.PointerUp
- }
- }
- };
+ TouchController.TouchUp(); //Complete the touch.
- // Inject the touch input.
- _inputInjector.InjectTouchInput(touchData);
- }*/
+ });
+ t.IsBackground = true;
+ t.Start();
}
}
}