Beispiel #1
0
        public static void SimulateHold(Point point)
        {
            PointerTouchInfo[] contacts = new PointerTouchInfo[1];
            contacts[0] = CreateDefaultPointerTouchInfo(point.X, point.Y, 2, 1);

            // Touch down
            contacts[0].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            // Initial contact
            bool success = TouchInjector.InjectTouchInput(contacts.Length, contacts);

            // Touch update
            contacts[0].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            int steps = touchHoldTime / touchTimeResolution;

            // Move contact
            for (int i = 0; i < steps; i++)
            {
                success = TouchInjector.InjectTouchInput(contacts.Length, contacts);
                //new ManualResetEvent(false).WaitOne(touchTimeResolution);
            }

            // Release contact
            contacts[0].PointerInfo.PointerFlags = PointerFlags.UP;

            success = TouchInjector.InjectTouchInput(contacts.Length, contacts);
        }
        public void UpdateTuioCursor(TuioCursor tuioCursor)
        {
            _refreshTimer.Stop();

            int pid = tuioCursor.getCursorID();

            int i = _pointerTouchInfos.FindIndex(pti => pti.PointerInfo.PointerId == pid);

            if (i != -1)
            {
                int x = (int)((tuioCursor.getX() * (_screenRect.Width + _calibrationBuffer.Width)) + _calibrationBuffer.Left + _screenRect.Left);
                int y = (int)((tuioCursor.getY() * (_screenRect.Height + _calibrationBuffer.Height)) + _calibrationBuffer.Top + _screenRect.Top);

                PointerTouchInfo pointerTouchInfo = _pointerTouchInfos[i];
                pointerTouchInfo.PointerInfo.PointerFlags    = PointerFlags.UPDATE | PointerFlags.INRANGE | ((this.IsContactEnabled) ? PointerFlags.INCONTACT : PointerFlags.NONE);
                pointerTouchInfo.PointerInfo.PtPixelLocation = new PointerTouchPoint {
                    X = x, Y = y
                };
                pointerTouchInfo.ContactArea = new ContactArea
                {
                    Left   = x - CONTACT_AREA_RADIUS,
                    Right  = x + CONTACT_AREA_RADIUS,
                    Top    = y - CONTACT_AREA_RADIUS,
                    Bottom = y + CONTACT_AREA_RADIUS
                };
                _pointerTouchInfos[i] = pointerTouchInfo;

                Trace.WriteLine(string.Format("set cur {0} ({1}) {2} {3} {4} {5}", pid, tuioCursor.getSessionID(), x, y, tuioCursor.getMotionSpeed(), tuioCursor.getMotionAccel()), "TUIO");
            }
        }
Beispiel #3
0
        public override void InjectPointer(PointerData[] pointerData)
        {
            if (pointerData.Length > 256)
            {
                throw new ArgumentOutOfRangeException(paramName: string.Format(format: "The maximum number of simultaneous touch points is {0}.", arg0: 256U));
            }
            if (Log.OutImplementation != null)
            {
                foreach (var pointerData1 in pointerData)
                {
                    Log.Out(msg: "Inject Pointer: {0}", (object)pointerData1.ToString());
                }
            }
            var pointerTouchInfo = new PointerTouchInfo[pointerData.Length];

            for (var index = 0; index < pointerData.Length; ++index)
            {
                pointerTouchInfo[index] = TransformPointer(pointerData: pointerData[index], inputType: POINTER_INPUT_TYPE.TOUCH).data.touchInfo;
                PrunePointerFlags(pointerFlags: ref pointerTouchInfo[index].pointerInfo.pointerFlags);
            }

            if (!InternalNativeMethodsLegacy.InjectTouchInput(count: (uint)pointerTouchInfo.Length, pointerTouchInfo: pointerTouchInfo))
            {
                throw new Win32Exception(error: Marshal.GetLastWin32Error());
            }
        }
Beispiel #4
0
    public static IEnumerator TryPress(int x, int y)
    {
        var pointer = new PointerTouchInfo();

        //We can add different additional touch data
        pointer.TouchMasks = TouchMask.PRESSURE;
        pointer.Pressure   = 100;


        //Pointer ID is for gesture tracking
        pointer.PointerInfo.PointerId   = 1;
        pointer.PointerInfo.pointerType = PointerInputType.TOUCH;

        pointer.PointerInfo.PtPixelLocation.X = x;
        pointer.PointerInfo.PtPixelLocation.Y = y;

        pointer.PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.DOWN;

        TouchInjector.InjectTouchInput(1, new[] { pointer });

        //Hold touch for some time
        yield return(new WaitForSeconds(0.1f));

        pointer.PointerInfo.PointerFlags = PointerFlags.UPDATE;

        TouchInjector.InjectTouchInput(1, new[] { pointer });
    }
Beispiel #5
0
        public static void SimulatePinchAndZoom(Point first, Point second, bool zoomOut, int step = 1)
        {
            PointerTouchInfo[] contacts = new PointerTouchInfo[2];
            contacts[0] = CreateDefaultPointerTouchInfo(first.X, first.Y, 2, 1);
            contacts[1] = CreateDefaultPointerTouchInfo(second.X, second.Y, 2, 2);

            // Touch down
            contacts[0].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
            contacts[1].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            // Initial contact
            bool success = TouchInjector.InjectTouchInput(contacts.Length, contacts);

            // Touch update
            contacts[0].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
            contacts[1].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            int steps = (int)Math.Sqrt(Math.Pow(first.X - second.X, 2) + Math.Pow(first.Y - second.Y, 2)) / step;

            double deltaXRaw = Math.Abs((double)(first.X - second.X) / steps / 2);

            double deltaYRaw = Math.Abs((double)(first.Y - second.Y) / steps / 2);

            double deltaX = 0;
            double deltaY = 0;

            int direction;

            // if zoomOut move touch points closer
            if (zoomOut)
            {
                direction = +1;
            }
            else
            {
                direction = -1;
            }

            // Move contact
            for (int i = 0; i < steps; ++i)
            {
                deltaX += deltaXRaw;
                deltaY += deltaYRaw;
                contacts[0].Move(direction * (int)-deltaX, direction * (int)-deltaY);
                contacts[1].Move(direction * (int)deltaX, direction * (int)deltaY);
                success = TouchInjector.InjectTouchInput(contacts.Length, contacts);
                //new ManualResetEvent(false).WaitOne(touchTimeResolution);
                deltaX = deltaX - (int)deltaX;
                deltaY = deltaY - (int)deltaY;
            }

            // Release contacts
            contacts[0].PointerInfo.PointerFlags = PointerFlags.UP;
            contacts[1].PointerInfo.PointerFlags = PointerFlags.UP;

            success = TouchInjector.InjectTouchInput(contacts.Length, contacts);
        }
        public void processEventFrame(Provider.FrameEventArgs e)
        {
            touchscreenMutex.WaitOne();
            List<PointerTouchInfo> toFire = new List<PointerTouchInfo>();

            foreach (WiiContact contact in e.Contacts)
            {
                if (Settings.Default.pointer_customCursor && (contact.Type == ContactType.Hover || contact.Type == ContactType.EndFromHover))
                {
                    //If we are using the custom cursor and it's more than 1 touchpoints, we skip the hovering because otherwise it's not working with edge guestures for example.
                }
                else
                {
                    ContactType type = contact.Type;

                    if (Settings.Default.pointer_customCursor && (contact.Type == ContactType.EndToHover))
                    {
                        type = ContactType.End;
                    }

                    PointerTouchInfo touch = new PointerTouchInfo();
                    touch.PointerInfo.pointerType = PointerInputType.TOUCH;
                    touch.TouchFlags = TouchFlags.NONE;
                    //contact.Orientation = (uint)cur.getAngleDegrees();//this is only valid for TuioObjects
                    touch.Pressure = 0;
                    touch.TouchMasks = TouchMask.NONE;
                    touch.PointerInfo.PtPixelLocation.X = (int)contact.Position.X;
                    touch.PointerInfo.PtPixelLocation.Y = (int)contact.Position.Y;
                    touch.PointerInfo.PointerId = (uint)contact.ID;
                    touch.PointerInfo.PerformanceCount = e.Timestamp;

                    if (type == ContactType.Start)
                        touch.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                    else if (type == ContactType.Move)
                        touch.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                    else if (type == ContactType.End)
                        touch.PointerInfo.PointerFlags = PointerFlags.UP;
                    else if (type == ContactType.EndToHover)
                        touch.PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE;
                    else if (type == ContactType.Hover)
                        touch.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE;
                    else if (type == ContactType.EndFromHover)
                        touch.PointerInfo.PointerFlags = PointerFlags.UPDATE;

                    toFire.Add(touch);
                }
            }
            //fire the events
            if (toFire.Count > 0)
            {
                if (!TCD.System.TouchInjection.TouchInjector.InjectTouchInput(toFire.Count, toFire.ToArray()))
                {
                    Console.WriteLine("Could not send touch input, count " + toFire.Count);
                }
            }
            touchscreenMutex.ReleaseMutex();
        }
Beispiel #7
0
        public static void SimulateSwipe(Point start, Point end, int duration)
        {
            PointerTouchInfo[] contacts = new PointerTouchInfo[1];
            contacts[0] = CreateDefaultPointerTouchInfo(start.X, start.Y, 2, 0);

            // Touch down
            contacts[0].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            // Initial contact
            bool success = TouchInjector.InjectTouchInput(contacts.Length, contacts);

            // Touch update
            contacts[0].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            //CubicBezier cb = new CubicBezier(0.95, 0.05, 0.795, 0.035); // easeInExpo

            double frames = (duration / (touchTimeResolution + 0.3));

            double delta = (double)1 / frames / contactsPerFrame;

            int distanceX = end.X - start.X;
            int distanceY = end.Y - start.Y;

            int contactRadius = contacts[0].PointerInfo.PtPixelLocation.X - contacts[0].ContactArea.left;

            double topFrame = Math.Ceiling(frames);

            int contactsToSend = (int)(frames * contactsPerFrame);

            // Move contact
            for (int i = 0; i < contactsToSend; ++i)
            {
                double travelPercent = 0;                 //cb.GetSplineValue(delta * i);
                int    deltaX        = start.X + (int)(distanceX * travelPercent) - contacts[0].PointerInfo.PtPixelLocation.X;
                int    deltaY        = start.Y + (int)(distanceY * travelPercent) - contacts[0].PointerInfo.PtPixelLocation.Y;
                contacts[0].Move(deltaX, deltaY);
                success = TouchInjector.InjectTouchInput(contacts.Length, contacts);
                //if ( i % contactsPerFrame == 0 )
                //new ManualResetEvent(false).WaitOne(touchTimeResolution);
            }

            if (contacts[0].PointerInfo.PtPixelLocation.X < end.X || contacts[0].PointerInfo.PtPixelLocation.Y < end.Y)
            {
                int deltaX = end.X - contacts[0].PointerInfo.PtPixelLocation.X;
                int deltaY = end.Y - contacts[0].PointerInfo.PtPixelLocation.Y;
                contacts[0].Move(deltaX, deltaY);
                success = TouchInjector.InjectTouchInput(contacts.Length, contacts);
            }

            // Release contact
            contacts[0].PointerInfo.PointerFlags = PointerFlags.UP;

            success = TouchInjector.InjectTouchInput(contacts.Length, contacts);
        }
Beispiel #8
0
        private PointerTouchInfo MakePointerTouchInfo(PointerInputType pointer, PointerFlags click, int x, int y,
                                                      int radius, uint id, string type, uint orientation = 90, uint pressure = 32000)
        {
            var contact = new PointerTouchInfo
            {
                PointerInfo = { pointerType = pointer },
                TouchFlags  = TouchFlags.NONE,
                Orientation = orientation,
                Pressure    = pressure
            };


            if (type == "Start")
            {
                contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
            }
            else if (type == "Move")
            {
                contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
            }
            else if (type == "End")
            {
                contact.PointerInfo.PointerFlags = PointerFlags.UP;
            }
            else if (type == "EndToHover")
            {
                contact.PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE;
            }
            else if (type == "Hover")
            {
                contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE;
            }
            else if (type == "EndFromHover")
            {
                contact.PointerInfo.PointerFlags = PointerFlags.UPDATE;
            }

            contact.PointerInfo.PointerFlags |= click;

            contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
            contact.PointerInfo.PtPixelLocation.X = x;
            contact.PointerInfo.PtPixelLocation.Y = y;
            contact.PointerInfo.PointerId         = id;
            contact.ContactArea.left   = x - radius;
            contact.ContactArea.right  = x + radius;
            contact.ContactArea.top    = y - radius;
            contact.ContactArea.bottom = y + radius;
            return(contact);
        }
Beispiel #9
0
        public void TouchUpdate(PointerTouchInfo touch, Point p)
        {
            if (!this._touches.Contains(touch))
            {
                throw new ArgumentException("touch");
            }

            touch.pointerInfo.pointerFlags    = PointerFlags.Update | PointerFlags.InRange | PointerFlags.InContact;
            touch.pointerInfo.ptPixelLocation =
                new POINT()
            {
                X = p.X, Y = p.Y
            };
            NativeMethod.InjectTouchInput((uint)this._touches.Count, this._touches.ToArray());
        }
Beispiel #10
0
        public override void InjectPointer(PointerData pointerData)
        {
            Log.Out(msg: "Inject Pointer: {0}", (object)pointerData.ToString());
            var pointerTouchInfo = new PointerTouchInfo[1] {
                new PointerTypeInfo[1] {
                    TransformPointer(pointerData: pointerData, inputType: POINTER_INPUT_TYPE.TOUCH)
                }[0].data.touchInfo
            };

            PrunePointerFlags(pointerFlags: ref pointerTouchInfo[0].pointerInfo.pointerFlags);
            if (!InternalNativeMethodsLegacy.InjectTouchInput(count: (uint)pointerTouchInfo.Length, pointerTouchInfo: pointerTouchInfo))
            {
                throw new Win32Exception(error: Marshal.GetLastWin32Error());
            }
        }
Beispiel #11
0
        public static void SimulateTap(Point point)
        {
            PointerTouchInfo[] contacts = new PointerTouchInfo[1];
            contacts[0] = CreateDefaultPointerTouchInfo(point.X, point.Y, 2, 1);

            // Touch down
            contacts[0].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            // Initial contact
            bool success = TouchInjector.InjectTouchInput(contacts.Length, contacts);

            // Release contact
            contacts[0].PointerInfo.PointerFlags = PointerFlags.UP;

            success = TouchInjector.InjectTouchInput(contacts.Length, contacts);
        }
    // Start is called before the first frame update
    void Start()
    {
        TouchInjector.InitializeTouchInjection(10, TouchFeedback.NONE);
        touches     = new PointerTouchInfo[1];
        touchInfo   = new PointerTouchInfo();
        pointerInfo = new PointerInfo();

        touchInfo.TouchFlags = TouchFlags.NONE;
        touchInfo.TouchMasks = TouchMask.NONE;

        pointerInfo.pointerType  = PointerInputType.TOUCH;
        pointerInfo.PointerId    = 0;
        pointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UPDATE;

        touchInfo.PointerInfo = pointerInfo;
    }
Beispiel #13
0
        public static PointerTouchInfo CreateDefaultPointerTouchInfo(int x, int y, int radius, uint id)
        {
            PointerTouchInfo contact = new PointerTouchInfo();

            contact.PointerInfo.pointerType = PointerInputType.TOUCH;
            contact.TouchFlags = TouchFlags.NONE;
            contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
            contact.PointerInfo.PtPixelLocation.X = x;
            contact.PointerInfo.PtPixelLocation.Y = y;
            contact.PointerInfo.PointerId         = id;
            contact.ContactArea.left   = x - radius;
            contact.ContactArea.right  = x + radius;
            contact.ContactArea.top    = y - radius;
            contact.ContactArea.bottom = y + radius;
            contact.Orientation        = 130;      //See the angle changed from default value 90 to 130
            return(contact);
        }
        public void RemoveTuioCursor(TuioCursor tuioCursor)
        {
            _refreshTimer.Stop();

            int pid = tuioCursor.getCursorID();

            int i = _pointerTouchInfos.FindIndex(pti => pti.PointerInfo.PointerId == pid);

            if (i != -1)
            {
                PointerTouchInfo pointerTouchInfo = _pointerTouchInfos[i];
                pointerTouchInfo.PointerInfo.PointerFlags = PointerFlags.UP;
                _pointerTouchInfos[i] = pointerTouchInfo;

                Trace.WriteLine(string.Format("del cur {0} ({1})", pid, tuioCursor.getSessionID()), "TUIO");
            }
        }
        public void Refresh(TuioTime frameTime)
        {
            Trace.WriteLine(string.Format("refresh {0}", frameTime.getTotalMilliseconds()), "TUIO");

            _refreshTimer.Stop();

            if (this.IsContactEnabled && this.IsWindowsKeyPressEnabled)
            {
                if (_pointerTouchInfos.Count.Equals(this.WindowsKeyPressTouchCount))
                {
#pragma warning disable 4014
                    InjectWindowsKeyPress();
#pragma warning restore 4014
                    return;
                }
            }

            InjectPointerTouchInfos();

            if (_pointerTouchInfos.Count > 0)
            {
                for (int i = _pointerTouchInfos.Count - 1; i >= 0; i--)
                {
                    if (_pointerTouchInfos[i].PointerInfo.PointerFlags.HasFlag(PointerFlags.UP))
                    {
                        _pointerTouchInfos.RemoveAt(i);
                    }
                }

                if (_pointerTouchInfos.Count > 0)
                {
                    for (int i = 0, ic = _pointerTouchInfos.Count; i < ic; i++)
                    {
                        if (_pointerTouchInfos[i].PointerInfo.PointerFlags.HasFlag(PointerFlags.DOWN))
                        {
                            PointerTouchInfo pointerTouchInfo = _pointerTouchInfos[i];
                            pointerTouchInfo.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | ((this.IsContactEnabled) ? PointerFlags.INCONTACT : PointerFlags.NONE);
                            _pointerTouchInfos[i] = pointerTouchInfo;
                        }
                    }

                    _refreshTimer.Start();
                }
            }
        }
Beispiel #16
0
 public static PointerTouchInfo MakePointerTouchInfo(int x, int y, int radius, uint id, 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.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
     contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
     contact.PointerInfo.PtPixelLocation.X = x;
     contact.PointerInfo.PtPixelLocation.Y = y;
     contact.PointerInfo.PointerId = id;
     contact.ContactArea.left = x - radius;
     contact.ContactArea.right = x + radius;
     contact.ContactArea.top = y - radius;
     contact.ContactArea.bottom = y + radius;
     return contact;
 }
Beispiel #17
0
        public static PointerTouchInfo MakePointerTouchInfo(int x, int y, uint id, int radius = 1, uint orientation = 90, uint pressure = 32000) //radius unused
        {
            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;
            contact.PointerInfo.PointerId         = id;
            //contact.ContactArea.left = x - radius;
            //contact.ContactArea.right = x + radius;
            //contact.ContactArea.top = y - radius;
            //contact.ContactArea.bottom = y + radius;
            return(contact);
        }
Beispiel #18
0
        public void TouchUp(PointerTouchInfo touch, Point p)
        {
            if (!this._touches.Contains(touch))
            {
                throw new ArgumentException("touch");
            }

            //touch.pointerInfo.pointerFlags = PointerFlags.Up | PointerFlags.InRange | PointerFlags.InContact;
            //touch.pointerInfo.ptPixelLocation =
            //    new POINT() { X = p.X, Y = p.Y };
            this._touches.Remove(touch);
            NativeMethod.InjectTouchInput((uint)this._touches.Count, this._touches.ToArray());

            if (this._touches.Count == 0)
            {
                this._initialized = false;
            }
        }
Beispiel #19
0
        private PointerTouchInfo MakePointerTouchInfo(int x, int y, int radius, uint id, 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.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
            contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
            contact.PointerInfo.PtPixelLocation.X = x;
            contact.PointerInfo.PtPixelLocation.Y = y;
            contact.PointerInfo.PointerId         = id;
            contact.ContactArea.left   = x - radius;
            contact.ContactArea.right  = x + radius;
            contact.ContactArea.top    = y - radius;
            contact.ContactArea.bottom = y + radius;
            return(contact);
        }
Beispiel #20
0
 private void TouchInjectionService_TouchInjected(object sender, TouchInjectedEventArgs e)
 {
     Application.Current.Dispatcher.BeginInvoke(new Action(() =>
     {
         List <Point> touchMarkers = new List <Point>();
         for (int i = 0, ic = e.PointerTouchInfos.Length; i < ic; i++)
         {
             PointerTouchInfo pointerTouchInfo = e.PointerTouchInfos[i];
             if (pointerTouchInfo.PointerInfo.PointerFlags.HasFlag(PointerFlags.UP))
             {
                 continue;
             }
             touchMarkers.Add(new Point
                              (
                                  (((pointerTouchInfo.PointerInfo.PtPixelLocation.X - this.TouchInjectionService.ScreenRect.Left) / this.TouchInjectionService.ScreenRect.Width) * this.CalibrationPanelSize.Width) - _touchMarkerRadius,
                                  (((pointerTouchInfo.PointerInfo.PtPixelLocation.Y - this.TouchInjectionService.ScreenRect.Top) / this.TouchInjectionService.ScreenRect.Height) * this.CalibrationPanelSize.Height) - _touchMarkerRadius
                              ));
         }
         this.TouchMarkers = touchMarkers;
     }), DispatcherPriority.Normal);
 }
Beispiel #21
0
        void HandleTouchDown()
        {
            if (isTouching)
            {
                ReleaseTouch();
            }

            VRControllerState_t cState = new VRControllerState_t();

            OpenVR.System.GetControllerState(OpenVR.Overlay.GetPrimaryDashboardDevice(), ref cState, cStateSize);

            touch = new PointerTouchInfo();
            touch.PointerInfo.pointerType = PointerInputType.TOUCH;
            touch.TouchFlags  = TouchFlags.NONE;
            touch.Orientation = 0;
            touch.Pressure    = 32000;//(uint)(cState.rAxis3.x * 2048);
            touch.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
            touch.TouchMasks = TouchMask.PRESSURE | TouchMask.CONTACTAREA;

            touch.PointerInfo.PtPixelLocation.X = _screenObject.Bounds.Left + (int)Math.Round((double)eventData.data.mouse.x);
            touch.PointerInfo.PtPixelLocation.Y = _screenObject.Bounds.Bottom - ((int)Math.Round((double)eventData.data.mouse.y) + touchYOffset);

            touch.ContactArea.top    = touch.PointerInfo.PtPixelLocation.Y - 3;
            touch.ContactArea.bottom = touch.PointerInfo.PtPixelLocation.Y + 3;

            touch.ContactArea.left  = touch.PointerInfo.PtPixelLocation.X - 6;
            touch.ContactArea.right = touch.PointerInfo.PtPixelLocation.X + 3;

            touch.PointerInfo.PointerId = 10;

            if (!TouchInjector.InjectTouchInput(1, new PointerTouchInfo[] { touch }))
            {
                Logger.Warning("[DESKTOP] Failed to inject touch down: " + GetLastError());
            }
            else
            {
                isTouching = true;
            }
        }
Beispiel #22
0
        private List <String> DumpPointerTouchInfo(PointerTouchInfo contact)
        {
            var lst = new List <String>();

            lst.Add("PointerInfo.pointerType = " + contact.PointerInfo.pointerType);
            lst.Add("TouchFlags = " + contact.TouchFlags);
            lst.Add("Orientation = " + contact.Orientation);
            lst.Add("Pressure = " + contact.Pressure);
            lst.Add("PointerInfo.PointerFlags = " + contact.PointerInfo.PointerFlags);
            lst.Add("TouchMasks = " + contact.TouchMasks);
            lst.Add("PointerInfo.PtPixelLocation.X = " + contact.PointerInfo.PtPixelLocation.X);
            lst.Add("PointerInfo.PtPixelLocation.Y = " + contact.PointerInfo.PtPixelLocation.Y);
            lst.Add("PointerInfo.PointerId = " + contact.PointerInfo.PointerId);
            lst.Add("ContactArea.left = " + contact.ContactArea.left);
            lst.Add("ContactArea.right = " + contact.ContactArea.right);
            lst.Add("ContactArea.top = " + contact.ContactArea.top);
            lst.Add("ContactArea.bottom = " + contact.ContactArea.bottom);


            lst.Add("pointerType = " + contact.PointerInfo.pointerType);
            lst.Add("PointerId = " + contact.PointerInfo.PointerId);
            lst.Add("FrameId = " + contact.PointerInfo.FrameId);
            lst.Add("PointerFlags = " + contact.PointerInfo.PointerFlags);
            lst.Add("SourceDevice = " + contact.PointerInfo.SourceDevice);
            lst.Add("WindowTarget = " + contact.PointerInfo.WindowTarget);
            lst.Add("PtPixelLocation = " + contact.PointerInfo.PtPixelLocation);
            lst.Add("PtPixelLocationRaw = " + contact.PointerInfo.PtPixelLocationRaw);
            lst.Add("PtHimetricLocation = " + contact.PointerInfo.PtHimetricLocation);
            lst.Add("PtHimetricLocationRaw = " + contact.PointerInfo.PtHimetricLocationRaw);
            lst.Add("Time = " + contact.PointerInfo.Time);
            lst.Add("HistoryCount = " + contact.PointerInfo.HistoryCount);
            lst.Add("InputData = " + contact.PointerInfo.InputData);
            lst.Add("KeyStates = " + contact.PointerInfo.KeyStates);
            lst.Add("PerformanceCount = " + contact.PointerInfo.PerformanceCount);
            lst.Add("ButtonChangeType = " + contact.PointerInfo.ButtonChangeType);

            return(lst);
        }
Beispiel #23
0
        public PointerTouchInfo TouchDown(Point p)
        {
            if (this._touches.Count == 0 && !this._initialized)
            {
                InitializeTouch();
            }

            PointerTouchInfo res = (new Data.PointerTouchInfo()
            {
                pointerInfo = new Data.POINTER_INFO()
                {
                    pointerType = POINTER_INPUT_TYPE.PT_TOUCH,
                    pointerFlags = PointerFlags.Down | PointerFlags.InRange | PointerFlags.InContact,
                    ptPixelLocation = new Data.POINT()
                    {
                        X = p.X,
                        Y = p.Y
                    },
                    pointerId = 0
                },
                touchFlags = TOUCH_FLAGS.TOUCH_FLAGS_NONE,
                orientation = 90,
                pressure = 32000,
                touchMask = TouchMask.ContactArea | TouchMask.Orientation | TouchMask.Pressure,
                rcContact = new RECT()
                {
                    left = p.X - _marge,
                    right = p.X + _marge,
                    top = p.Y - _marge,
                    bottom = p.Y + _marge,
                }
            });

            this._touches.Add(res);

            NativeMethod.InjectTouchInput((uint)this._touches.Count, this._touches.ToArray());
            return(res);
        }
        /// <summary>
        /// Finger down on the screen
        /// </summary>
        /// <param name="x">The X coordinate on the screen</param>
        /// <param name="y">The Y coordinate on the screen</param>
        /// <returns>true if successful, otherwise false</returns>
        public static bool TouchDown(int x, int y)
        {
            InitializeTouchInjection();

            _contact = new PointerTouchInfo();
            _contact.PointerInfo.pointerType       = PointerInputType.TOUCH;
            _contact.PointerInfo.PointerId         = 0;
            _contact.PointerInfo.PtPixelLocation.X = x;
            _contact.PointerInfo.PtPixelLocation.Y = y;

            _contact.TouchFlags  = TouchFlags.NONE;
            _contact.TouchMasks  = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
            _contact.Orientation = 90;
            _contact.Pressure    = 32000;

            _contact.ContactArea.top    = _contact.PointerInfo.PtPixelLocation.Y - 2;
            _contact.ContactArea.bottom = _contact.PointerInfo.PtPixelLocation.Y + 2;
            _contact.ContactArea.left   = _contact.PointerInfo.PtPixelLocation.X - 2;
            _contact.ContactArea.right  = _contact.PointerInfo.PtPixelLocation.X + 2;

            _contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            return(TouchInjector.InjectTouchInput(1, new [] { _contact }));
        }
        public void processEventFrame(Provider.FrameEventArgs e)
        {
            touchscreenMutex.WaitOne();
            List <PointerTouchInfo> toFire = new List <PointerTouchInfo>();

            foreach (WiiContact contact in e.Contacts)
            {
                if (Settings.Default.pointer_customCursor && (contact.Type == ContactType.Hover || contact.Type == ContactType.EndFromHover))
                {
                    //If we are using the custom cursor and it's more than 1 touchpoints, we skip the hovering because otherwise it's not working with edge guestures for example.
                }
                else
                {
                    ContactType type = contact.Type;

                    if (Settings.Default.pointer_customCursor && (contact.Type == ContactType.EndToHover))
                    {
                        type = ContactType.End;
                    }

                    PointerTouchInfo touch = new PointerTouchInfo();
                    touch.PointerInfo.pointerType = PointerInputType.TOUCH;
                    touch.TouchFlags = TouchFlags.NONE;
                    //contact.Orientation = (uint)cur.getAngleDegrees();//this is only valid for TuioObjects
                    touch.Pressure   = 0;
                    touch.TouchMasks = TouchMask.NONE;
                    touch.PointerInfo.PtPixelLocation.X = (int)contact.Position.X;
                    touch.PointerInfo.PtPixelLocation.Y = (int)contact.Position.Y;
                    touch.PointerInfo.PointerId         = (uint)contact.ID;
                    touch.PointerInfo.PerformanceCount  = e.Timestamp;

                    if (type == ContactType.Start)
                    {
                        touch.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                    }
                    else if (type == ContactType.Move)
                    {
                        touch.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                    }
                    else if (type == ContactType.End)
                    {
                        touch.PointerInfo.PointerFlags = PointerFlags.UP;
                    }
                    else if (type == ContactType.EndToHover)
                    {
                        touch.PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE;
                    }
                    else if (type == ContactType.Hover)
                    {
                        touch.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE;
                    }
                    else if (type == ContactType.EndFromHover)
                    {
                        touch.PointerInfo.PointerFlags = PointerFlags.UPDATE;
                    }

                    toFire.Add(touch);
                }
            }
            //fire the events
            if (toFire.Count > 0)
            {
                if (!TCD.System.TouchInjection.TouchInjector.InjectTouchInput(toFire.Count, toFire.ToArray()))
                {
                    Console.WriteLine("Could not send touch input, count " + toFire.Count);
                }
            }
            touchscreenMutex.ReleaseMutex();
        }
Beispiel #26
0
        public static void Run(FingerList Fingers)
        {
            List <Finger> sortedFingers = Fingers.OrderBy(Finger => Finger.TimeVisible).ToList();

            sortedFingers.Reverse();

            List <TouchContact>     updatedContacts = new List <TouchContact>();
            List <PointerTouchInfo> toInject        = new List <PointerTouchInfo>();

            for (int i = 0; i <= sortedFingers.Count - 1; i++)
            {
                int   ID   = sortedFingers[i].Id;
                int   xPos = (int)(sortedFingers[i].TipPosition.x * Properties.Settings.Default.TouchCursorSpeed) + 1000;  //1000
                int   yPos = -(int)(sortedFingers[i].TipPosition.y * Properties.Settings.Default.TouchCursorSpeed) + 3300; // speed 15: add 2500
                float zPos = sortedFingers[i].TipPosition.z;

                updatedContacts.Add(new TouchContact(xPos, yPos, zPos, ID));

                int foundIndex = contacts.FindIndex(TouchContact => TouchContact.ID == updatedContacts[i].ID);
                if (foundIndex >= 0) //a matching ID was found
                {
                    //transfer the data to the updated contacts
                    updatedContacts[i].Holding      = contacts[foundIndex].Holding;
                    updatedContacts[i].JustPressed  = contacts[foundIndex].JustPressed;
                    updatedContacts[i].JustReleased = contacts[foundIndex].JustReleased;
                }
            }
            // sort the contacts by ID so they keep consistent indexes over time
            //contacts = updatedContacts.OrderBy(TouchContact => TouchContact.ID).ToList();
            contacts = updatedContacts;


            for (int i = 0; i <= sortedFingers.Count - 1; i++)
            {
                PointerTouchInfo touchPoint = MakePointerTouchInfo(contacts[i].PosX, contacts[i].PosY, (uint)contacts[i].ID);

                if (i <= injector.Length - 1)
                {
                    //injector[i].PointerInfo.PointerId = (uint)contacts[i].ID;

                    if (contacts[i].PosZ < Properties.Settings.Default.TouchThreshold && contacts[i].Holding == false) // pressed
                    {
                        contacts[i].JustPressed = true;
                        contacts[i].Holding     = true;
                    }

                    if (contacts[i].PosZ > Properties.Settings.Default.TouchThreshold && contacts[i].Holding == true) // released
                    {
                        contacts[i].JustReleased = true;
                        contacts[i].Holding      = false;
                    }


                    if (contacts[i].JustPressed)
                    {
                        contacts[i].JustPressed             = false;
                        touchPoint.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                    }
                    else if (contacts[i].JustReleased)
                    {
                        contacts[i].JustReleased            = false;
                        touchPoint.PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE;
                    }
                    else if (contacts[i].Holding)
                    {
                        touchPoint.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                    }
                    else
                    {
                        touchPoint.PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UPDATE; //set to "hover mode"
                    }

                    toInject.Add(touchPoint);
                }
            }

            //injector.Length
            bool s = TouchInjector.InjectTouchInput(toInject.Count, toInject.ToArray());


            SettingsWindow.debugText[2] = "contacts: ";
            foreach (TouchContact c in contacts)
            {
                SettingsWindow.debugText[2] += " " + c.ID; //  + " " + c.Holding
            }
            //List<TouchContact> newContacts = new List<TouchContact>();

            ////List<PointerTouchInfo> toFire = new List<PointerTouchInfo>();

            //foreach (Finger finger in Fingers)
            //{

            //    int xPos = (int)(finger.TipPosition.x * multFactor) + 1000; // speed 15: 1000
            //    int yPos = -(int)(finger.TipPosition.y * multFactor) + 2500; // speed 15: add 2500
            //    float zPos = finger.TipPosition.z;

            //    //injectorList.Add(MakePointerTouchInfo(xPos, yPos, (uint)finger.Id));
            //    newContacts.Add(new TouchContact(xPos, yPos, zPos, finger.Id));
            //}

            ////injector = injectorList.ToArray();
            ////injectorList.Clear();


            //List<TouchContact> updatedContacts = new List<TouchContact>();
            //int foundIndex;

            ////todo: combine with foreach finger loop
            ////newContacts.Count - 1
            //for (int i = 0; i <= newContacts.Count - 1; i++)
            //{
            //    updatedContacts.Add(newContacts[i]);

            //    foundIndex = contacts.FindIndex(TouchContact => TouchContact.ID == updatedContacts[i].ID);
            //    if (foundIndex >= 0) //a matching ID was found
            //    {
            //        //transfer the data to the updated contacts
            //        updatedContacts[i].Holding = contacts[foundIndex].Holding;
            //        updatedContacts[i].JustPressed = contacts[foundIndex].JustPressed;
            //        updatedContacts[i].JustReleased = contacts[foundIndex].JustReleased;
            //    }
            //}

            //contacts = updatedContacts;


            ////contacts.Count - 1
            //for (int i = 0; i <= Fingers.Count - 1; i++)
            //{
            //    if (i <= injector.Length - 1)
            //    {
            //        //injector[i].PointerInfo.PointerId = (uint)contacts[i].ID;

            //        if (contacts[i].PosZ < touchThreshold && contacts[i].Holding == false) // pressed
            //        {
            //            contacts[i].JustPressed = true;
            //            contacts[i].Holding = true;
            //        }

            //        if (contacts[i].PosZ > touchThreshold && contacts[i].Holding == true) // released
            //        {
            //            contacts[i].JustReleased = true;
            //            contacts[i].Holding = false;
            //        }


            //        if (contacts[i].JustPressed)
            //        {
            //            contacts[i].JustPressed = false;
            //            injector[i].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
            //        }
            //        else if (contacts[i].JustReleased)
            //        {
            //            contacts[i].JustReleased = false;
            //            injector[i].PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE;
            //        }
            //        else if (contacts[i].Holding)
            //        {
            //            injector[i].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
            //        }
            //        else
            //        {
            //            injector[i].PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UPDATE; //set to "hover mode"
            //        }

            //        injector[i].PointerInfo.PtPixelLocation.X = (int)(Fingers[i].TipPosition.x * multFactor) + 800; // speed 15: 1000
            //        injector[i].PointerInfo.PtPixelLocation.Y = -(int)(Fingers[i].TipPosition.y * multFactor) + 1800; // speed 15: add 2500
            //    }

            //}

            ////Form1.debugText[3] = "Fingers:  ";
            ////foreach (Finger f in Fingers)
            ////    Form1.debugText[3] += " " + f.Id;

            ////if (released)
            ////    Form1.debugText[3] += "r";

            ////released = false;


            ////injector.Length
            //bool s = TouchInjector.InjectTouchInput(Fingers.Count, injector);

            ////Form1.debugText[1] = "Injector length: " + injector.Length + "  contacts count: " + contacts.Count;



            //Form1.debugText[2] = "contacts: ";
            //foreach (TouchContact c in contacts)
            //    Form1.debugText[2] += " " + c.ID + " " + c.Holding;

            ////Form1.debugText[3] = "";

            ////Form1.debugText[4] = "" + s;
        }
        /// <summary>
        /// Finger down on the screen
        /// </summary>
        /// <param name="x">The X coordinate on the screen</param>
        /// <param name="y">The Y coordinate on the screen</param>
        /// <returns>true if successful, otherwise false</returns>
        public static bool TouchDown(int x, int y)
        {
            InitializeTouchInjection();

            _contact = new PointerTouchInfo();
            _contact.PointerInfo.pointerType = PointerInputType.TOUCH;
            _contact.PointerInfo.PointerId = 0;
            _contact.PointerInfo.PtPixelLocation.X = x;
            _contact.PointerInfo.PtPixelLocation.Y = y;

            _contact.TouchFlags = TouchFlags.NONE;
            _contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
            _contact.Orientation = 90;
            _contact.Pressure = 32000;

            _contact.ContactArea.top = _contact.PointerInfo.PtPixelLocation.Y - 2;
            _contact.ContactArea.bottom = _contact.PointerInfo.PtPixelLocation.Y + 2;
            _contact.ContactArea.left = _contact.PointerInfo.PtPixelLocation.X - 2;
            _contact.ContactArea.right = _contact.PointerInfo.PtPixelLocation.X + 2;

            _contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;

            return TouchInjector.InjectTouchInput(1, new [] { _contact });
        }
Beispiel #28
0
 public void TouchUp(PointerTouchInfo touch)
 {
     this.TouchUp(touch, Point.Empty);
 }
Beispiel #29
0
        private void TuioChannel_OnTuioRefresh(TuioTime t)
        {
            //TODO: re-enable frequent screen monitoring
            //if (frameCount % checkScreenEvery == 0)
            //    ScanScreens();
            //loop through the TuioObjects
            List <PointerTouchInfo> toFire     = new List <PointerTouchInfo>();
            List <long>             removeList = new List <long>();

            foreach (var kvp in channel.CursorList)
            {
                TuioCursor   cur  = kvp.Value.TuioCursor;
                IncomingType type = kvp.Value.Type;
                int[]        injectionCoordinates = ToInjectionCoordinates(cur.X, cur.Y);
                int          radius = 12;
                //make a new pointertouchinfo with all neccessary information
                PointerTouchInfo contact = new PointerTouchInfo();
                contact.PointerInfo.pointerType = PointerInputType.TOUCH;
                contact.TouchFlags = TouchFlags.NONE;
                //contact.Orientation = (uint)cur.getAngleDegrees();//this is only valid for TuioObjects
                contact.Pressure   = 1024;
                contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE;
                contact.PointerInfo.PtPixelLocation.X = injectionCoordinates[0];
                contact.PointerInfo.PtPixelLocation.Y = injectionCoordinates[1];
                contact.PointerInfo.PointerId         = (uint)cur.CursorID;

                contact.ContactArea.left   = injectionCoordinates[0] - radius;
                contact.ContactArea.right  = injectionCoordinates[0] + radius;
                contact.ContactArea.top    = injectionCoordinates[1] - radius;
                contact.ContactArea.bottom = injectionCoordinates[1] + radius;
                //contact.PointerInfo.FrameId = frameCount;

                //set the right flags
                if (type == IncomingType.New)
                {
                    contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                    kvp.Value.Type = IncomingType.Update;
                }
                else if (type == IncomingType.Update)
                {
                    contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                }
                else if (type == IncomingType.Remove)
                {
                    contact.PointerInfo.PointerFlags = PointerFlags.UP;
                    removeList.Add(kvp.Key);
                }

                //add it to 'toFire'
                toFire.Add(contact);
            }

            //fire the events
            bool success = TCD.System.TouchInjection.TouchInjector.InjectTouchInput(toFire.Count, toFire.ToArray());

            //remove those with type == IncomingType.Remove
            foreach (long key in removeList)
            {
                channel.CursorList.Remove(key);//remove from the tuio channel
            }
            //count up
            frameCount++;
        }
Beispiel #30
0
        public void Install()
        {
            var thread = new Thread(() =>
            {
                _win = new InputTargetWindow();

                var ok = RegisterPointerInputTarget(_win.Handle, PointerInputType.TOUCH);
                if (!ok)
                {
                    Debug.WriteLine("失败 RegisterPointerInputTarget: " + Native.GetLastError());
                    return; //todo: !!
                }
                else
                {
                    Debug.WriteLine("TouchHook Installed.");
                }

                Native.MSG msg;
                int ret;

                var sim = new InputSimulator();

                TouchInjector.InitializeTouchInjection();
                var screenBounds = Rectangle.Empty;

                var contacts         = new PointerTouchInfo[10];
                uint contactCount    = 10;
                uint startingPointId = 0;

                while ((ret = Native.GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0)
                {
                    if (ret == -1)
                    {
                        Debug.WriteLine("Error!");
                        continue;
                    }
                    var pointerId = GET_POINTERID_WPARAM((uint)msg.wParam.ToInt32());

                    if (!GetPointerFrameTouchInfo(pointerId, ref contactCount, contacts))
                    {
                        Debug.WriteLine("GetPointerFrameTouchInfo Error: " + Native.GetLastError());
                        continue;
                    }

                    //TODO: refactor... just hacking...
                    switch (msg.message)
                    {
                    case WM_POINTERDOWN:
                        Debug.WriteLine("Touch Down: " + contactCount);

                        if (contactCount == 3)
                        {
                            startingPointId = contacts[0].PointerInfo.PointerId;
                            if (screenBounds.Width > 0 && screenBounds.Height > 0)
                            {
                                var pos = contacts[0].PointerInfo.PtPixelLocation;
                                User32.SetCursorPos(pos.X, pos.Y);
                            }
                            screenBounds = Native.GetScreenBounds();
                            sim.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.LWIN);
                            continue;
                        }
                        ConvertToNewTouchInfo(contacts, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT);
                        if (!TouchInjector.InjectTouchInput(1, contacts))
                        {
                            Debug.WriteLine("Error InjectTouchInput: " + Native.GetLastError());
                        }
                        break;

                    case WM_POINTERUPDATE:
                        Debug.Write('.');

                        if (contactCount == 3)
                        {
                            TouchPoint?pos = null;
                            foreach (var contact in contacts)
                            {
                                if (contact.PointerInfo.PointerId == startingPointId)
                                {
                                    pos = contact.PointerInfo.PtPixelLocation;
                                }
                            }

                            if (pos != null && screenBounds.Width > 0 && screenBounds.Height > 0)
                            {
                                var absX = pos.Value.X * (65535.0 / screenBounds.Width);
                                var absY = pos.Value.Y * (65535.0 / screenBounds.Height);
                                sim.Mouse.MoveMouseTo(absX, absY);
                            }
                            continue;
                        }

                        ConvertToNewTouchInfo(contacts, PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT);
                        if (!TouchInjector.InjectTouchInput((int)contactCount, contacts))
                        {
                            Debug.WriteLine("Error InjectTouchInput: " + Native.GetLastError());
                        }

                        break;


                    case WM_POINTERUP:
                        Debug.WriteLine("Touch Up");
                        if (contactCount == 3)
                        {
                            sim.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.LWIN);
                            continue;
                        }
                        ConvertToNewTouchInfo(contacts, PointerFlags.UP);
                        if (!TouchInjector.InjectTouchInput(1, contacts))
                        {
                            Debug.WriteLine("Error InjectTouchInput: " + Native.GetLastError());
                        }
                        break;

                    case WM_POINTERENTER:
                        Debug.WriteLine("Touch Enter");
                        //ConvertToNewTouchInfo(contacts, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT);
                        continue;

                    case WM_POINTERLEAVE:
                        Debug.WriteLine("Touch Leave");
                        //ConvertToNewTouchInfo(contacts, PointerFlags.UP | PointerFlags.INRANGE | PointerFlags.INCONTACT);
                        continue;

                    default:
                        Debug.WriteLine("Unhandled Msg: " + msg.message);
                        continue;
                    }



                    var MSG = new Message()
                    {
                        HWnd = msg.hwnd, LParam = msg.lParam, WParam = msg.wParam, Msg = (int)msg.message, Result = IntPtr.Zero
                    };
                    _win.DefWndProc(ref MSG);
                }
            });

            thread.Start();
        }
Beispiel #31
0
        private void Instance_TabletEvent(object sender, Protocol.event_packet e)
        {
            Invoke(new MethodInvoker(delegate() {
                txtX.Text        = e.x.ToString();
                txtY.Text        = e.y.ToString();
                txtPressure.Text = e.pressure.ToString();
                txtButton.Text   = e.button.ToString();


                Win32Interop.POINT screenPos;
                screenPos.x = e.x * 1400 / 65535;
                screenPos.y = e.y * 800 / 65535;

                PointerTouchInfo[] touchEvent = new PointerTouchInfo[1];
                touchEvent[0] = MakePointerTouchInfo(screenPos.x, screenPos.y, (int)Math.Pow(2, Math.Max(1, e.pressure / 1000)), 1);

#if true
                if (e.type == Protocol.EVENT_TYPE_BUTTON && e.down != 0)
                {
                    e.type = Protocol.EVENT_TYPE_MOTION;
                }
                else if (e.type == Protocol.EVENT_TYPE_MOTION && e.pressure > 23000)
                {
                    if (!bIsDown)
                    {
                        e.type = Protocol.EVENT_TYPE_BUTTON;
                    }
                }
#endif

                if (e.type == GfxTabletWinDotnet.Protocol.EVENT_TYPE_MOTION)
                {
                    touchEvent[0].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INCONTACT | PointerFlags.INRANGE;
                }
                else
                {
                    if (e.button == 0)
                    {
                        bIsDown = true;
                        touchEvent[0].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INCONTACT | PointerFlags.INRANGE;
                    }
                    else
                    {
                        bIsDown = false;
                        touchEvent[0].PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INCONTACT | PointerFlags.INRANGE;
                    }
                }

                touchEvent[0].Pressure = (uint)e.pressure / 2;


                bool ok = TouchInjector.InjectTouchInput(1, touchEvent);
                if (!ok)
                {
                    ok = ok;
                }


                //Win32Interop.PointerTouchInfo[] touchEvent = new Win32Interop.PointerTouchInfo[1];


                //touchEvent[0].PointerInfo.pointerType = Win32Interop.POINTER_INPUT_TYPE.PT_TOUCH;
                //touchEvent[0].PointerInfo.PointerId = 0; //each finger leaving and entering may get a unique id. one is sufficient for our purposes
                ////touchEvent[0].PointerInfo.FrameId = (uint)(gUniqueFrameId++);
                ////touchEvent[0].pointerInfo.pointerFlags = Win32Interop.POINTER_FLAGS.POINTER_FLAG_INRANGE | Win32Interop.POINTER_FLAGS.POINTER_FLAG_INCONTACT | Win32Interop.POINTER_FLAGS.POINTER_FLAG_PRIMARY | Win32Interop.POINTER_FLAGS.POINTER_FLAG_UPDATE | Win32Interop.POINTER_FLAGS.POINTER_FLAG_DOWN;
                ////touchEvent[0].PointerInfo.SourceDevice = IntPtr.Zero;
                ////touchEvent[0].PointerInfo.WindowTarget = IntPtr.Zero; //window under mouse? probably assigend by windows
                //touchEvent[0].PointerInfo.PtPixelLocation.X = 640;
                //touchEvent[0].PointerInfo.PtPixelLocation.Y = 480;
                ////touchEvent[0].PointerInfo.PtHimetricLocation.X = 0;
                ////touchEvent[0].PointerInfo.PtHimetricLocation.Y = 0;
                ////touchEvent[0].PointerInfo.PtHimetricLocationRaw.X = 0;
                ////touchEvent[0].PointerInfo.PtHimetricLocationRaw.Y = 0;
                ////touchEvent[0].PointerInfo.Time = 0; // DateTime.Now.Ticks;
                //touchEvent[0].PointerInfo.HistoryCount = 1;
                ////touchEvent[0].PointerInfo.InputData = 0;
                ////touchEvent[0].PointerInfo.KeyStates = 0; //todo? probably assigned by windows
                ////touchEvent[0].PointerInfo.PerformanceCount = 0;
                ////touchEvent[0].pointerInfo.ButtonChangeType = Win32Interop.POINTER_BUTTON_CHANGE_TYPE.POINTER_CHANGE_NONE;

                //touchEvent[0].TouchFlags = Win32Interop.TouchFlags.NONE;

                //touchEvent[0].TouchMasks = Win32Interop.TouchMask.TOUCH_MASK_PRESSURE | Win32Interop.TouchMask.TOUCH_MASK_CONTACTAREA | Win32Interop.TouchMask.TOUCH_MASK_ORIENTATION;
                //touchEvent[0].Orientation = 90; //stift-neigung, default=0
                //touchEvent[0].ContactArea.left = touchEvent[0].PointerInfo.PtPixelLocation.X - 2;
                //touchEvent[0].ContactArea.top = touchEvent[0].PointerInfo.PtPixelLocation.Y - 2;
                //touchEvent[0].ContactArea.right = touchEvent[0].PointerInfo.PtPixelLocation.X + 2;
                //touchEvent[0].ContactArea.bottom = touchEvent[0].PointerInfo.PtPixelLocation.Y + 2;

                //touchEvent[0].Pressure = 32000; // (uint)Math.Min(1024, (int)e.pressure); //0-1024

                //if (e.down == 1)
                //{
                //	touchEvent[0].PointerInfo.PointerFlags = Win32Interop.POINTER_FLAGS.POINTER_FLAG_INRANGE | Win32Interop.POINTER_FLAGS.POINTER_FLAG_INCONTACT | Win32Interop.POINTER_FLAGS.POINTER_FLAG_DOWN;
                //	//touchEvent[0].pointerInfo.ButtonChangeType = Win32Interop.POINTER_BUTTON_CHANGE_TYPE.POINTER_CHANGE_FIRSTBUTTON_DOWN;
                //}
                //else if (e.down == 0)
                //{
                //	touchEvent[0].PointerInfo.PointerFlags = Win32Interop.POINTER_FLAGS.POINTER_FLAG_INRANGE | Win32Interop.POINTER_FLAGS.POINTER_FLAG_INCONTACT | Win32Interop.POINTER_FLAGS.POINTER_FLAG_UP;
                //	//touchEvent[0].pointerInfo.ButtonChangeType = Win32Interop.POINTER_BUTTON_CHANGE_TYPE.POINTER_CHANGE_FIRSTBUTTON_DOWN;
                //}

                //bool ok = Win32Interop.InjectTouchInput(1, touchEvent);
            }));
        }
Beispiel #32
0
        public MainWindow()
        {
            this.Loaded += MainWindow_Loaded;

            InitializeComponent();

            TouchInjector.InitializeTouchInjection();

            mainCanvas.Width  = Screen.PrimaryScreen.Bounds.Width;
            mainCanvas.Height = Screen.PrimaryScreen.Bounds.Height;

            BitmapImage bi0 = new BitmapImage();

            bi0.BeginInit();
            bi0.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor0.png");
            bi0.EndInit();

            BitmapImage bi1 = new BitmapImage();

            bi1.BeginInit();
            bi1.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor1.png");
            bi1.EndInit();

            cursorImageIndex.Source = bi0;
            cursorImageIndex.Width  = cursorImageIndex.Height = 100;

            cursorImageThumb.Source = bi0;
            cursorImageThumb.Width  = cursorImageThumb.Height = 100;

            cursorImageIndex.Opacity = 0;
            cursorImageThumb.Opacity = 0;

            IPC ipc = new IPC("win_cursor_plus");

            ipc.MapFunction("exit", delegate(string messageBody)
            {
                ipc.Clear();
                Environment.Exit(0);
                return(1);
            });

            ipc.SetUDPCallback(delegate(string message)
            {
                if (message != "hide_cursor_index" || message != "hide_cursor_thumb")
                {
                    string[] xyStr = message.Split('!');

                    if (xyStr.Length == 5)
                    {
                        cursorIndexDown = false;
                        cursorThumbDown = false;

                        float x;
                        float y;
                        float z;
                        int down;

                        bool b0 = float.TryParse(xyStr[0], System.Globalization.NumberStyles.Float, null, out x);
                        bool b1 = float.TryParse(xyStr[1], System.Globalization.NumberStyles.Float, null, out y);
                        bool b2 = float.TryParse(xyStr[2], System.Globalization.NumberStyles.Float, null, out z);
                        bool b3 = int.TryParse(xyStr[3], System.Globalization.NumberStyles.Float, null, out down);

                        if (b0 && b1 && b2)
                        {
                            if (xyStr[4] == "index")
                            {
                                xCursorIndex = x * screenWidth / 1000;
                                if (xCursorIndex < 0)
                                {
                                    xCursorIndex = 0;
                                }
                                else if (xCursorIndex > screenWidth)
                                {
                                    xCursorIndex = screenWidth;
                                }

                                yCursorIndex = y * screenHeight / 1000;
                                if (yCursorIndex < 0)
                                {
                                    yCursorIndex = 0;
                                }
                                else if (yCursorIndex > screenHeight)
                                {
                                    yCursorIndex = screenHeight;
                                }

                                zCursorIndex = z;

                                showCursorIndex = true;
                                cursorIndexDown = down == 1;
                            }
                            else if (xyStr[4] == "thumb")
                            {
                                xCursorThumb = x * screenWidth / 1000;
                                if (xCursorThumb < 0)
                                {
                                    xCursorThumb = 0;
                                }
                                else if (xCursorThumb > screenWidth)
                                {
                                    xCursorThumb = screenWidth;
                                }

                                yCursorThumb = y * screenHeight / 1000;
                                if (yCursorThumb < 0)
                                {
                                    yCursorThumb = 0;
                                }
                                else if (yCursorThumb > screenHeight)
                                {
                                    yCursorThumb = screenHeight;
                                }

                                zCursorThumb = z;

                                showCursorThumb = true;
                                cursorIndexDown = true;
                                cursorThumbDown = true;
                            }
                        }
                    }
                    else if (message == "hide_cursor_index")
                    {
                        showCursorIndex = false;
                    }
                    else if (message == "hide_cursor_thumb")
                    {
                        showCursorThumb = false;
                    }
                    else if (xyStr.Length == 2 && xyStr[0] == "update")
                    {
                        updateNumNew = int.Parse(xyStr[1]);
                    }
                }

                return(1);
            });

            Timer ipcTimer = new Timer();

            ipcTimer.Interval = 100;
            ipcTimer.Tick    += delegate(object o, EventArgs e)
            {
                ipc.Update();
            };
            ipcTimer.Start();

            Timer timer = new Timer();

            timer.Interval = 20;
            timer.Tick    += delegate(object o, EventArgs e)
            {
                if (updateNumNew == updateNumOld && showCursorIndex)
                {
                    return;
                }

                updateNumOld = updateNumNew;

                if (!useTUIO && showCursorIndex)
                {
                    if (!useFallback)
                    {
                        List <PointerTouchInfo> contacts = new List <PointerTouchInfo>();

                        if (cursorIndexDown && !cursorIndexDownOld)
                        {
                            PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndex, (int)yCursorIndex, 2, 1);
                            contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                            contacts.Add(contact);
                        }
                        else if (cursorIndexDown && cursorIndexDownOld)
                        {
                            PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndex, (int)yCursorIndex, 2, 1);
                            contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                            contacts.Add(contact);
                        }
                        else if (!cursorIndexDown && cursorIndexDownOld)
                        {
                            PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndexOld, (int)yCursorIndexOld, 2, 1);
                            contact.PointerInfo.PointerFlags = PointerFlags.UP;
                            contacts.Add(contact);
                        }

                        if (cursorThumbDown && !cursorThumbDownOld)
                        {
                            PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumb, (int)yCursorThumb, 2, 2);
                            contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                            contacts.Add(contact);
                        }
                        else if (cursorThumbDown && cursorThumbDownOld)
                        {
                            PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumb, (int)yCursorThumb, 2, 2);
                            contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                            contacts.Add(contact);
                        }
                        else if (!cursorThumbDown && cursorThumbDownOld)
                        {
                            PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumbOld, (int)yCursorThumbOld, 2, 2);
                            contact.PointerInfo.PointerFlags = PointerFlags.UP;
                            contacts.Add(contact);
                        }

                        bool success = TouchInjector.InjectTouchInput(contacts.Count, contacts.ToArray());
                    }
                    else
                    {
                        System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)xCursorIndex, (int)yCursorIndex);

                        if (cursorIndexDown)
                        {
                            mouseDown();
                        }
                        else
                        {
                            mouseUp();
                        }
                    }
                }
                else if (showCursorIndex)
                {
                    Object[]  tCur0  = new Object[7];
                    Object[]  tCur1  = new Object[7];
                    OSCBundle bundle = new OSCBundle();
                    bundle.Append(TUIO.TUIOFseq(tuioFSeq));
                    ArrayList TUIOSessions = new ArrayList();

                    if (cursorIndexDown)
                    {
                        bundle.Append(TUIO.TUIO2DcurExt(0, xCursorIndex / screenWidth, yCursorIndex / screenHeight, 0, 0, 0, 10, 10));
                        TUIOSessions.Add(0);
                    }
                    if (cursorThumbDown)
                    {
                        bundle.Append(TUIO.TUIO2DcurExt(1, xCursorThumb / screenWidth, yCursorThumb / screenHeight, 0, 0, 0, 10, 10));
                        TUIOSessions.Add(1);
                    }
                    bundle.Append(TUIO.TUIOAlive(TUIOSessions));
                    transmitter.Send(bundle);
                    tuioFSeq++;
                }

                if (showCursorIndex)
                {
                    if (cursorIndexDown)
                    {
                        cursorImageIndex.Source = bi1;
                    }
                    else
                    {
                        cursorImageIndex.Source = bi0;
                    }

                    if (cursorImageIndex.Opacity < 1)
                    {
                        cursorImageIndex.Opacity += 0.2;
                    }

                    int cursorSize = (int)(zCursorIndex * 5 * (float)windowWidth / (float)screenWidth);
                    if (cursorSize > 150)
                    {
                        cursorSize = 150;
                    }
                    else if (cursorSize < 50)
                    {
                        cursorSize = 50;
                    }

                    cursorImageIndex.Width = cursorImageIndex.Height = cursorSize;

                    int xPosRemapped = (int)map_val(xCursorIndex, 0, screenWidth, 0, windowWidth);
                    int yPosRemapped = (int)map_val(yCursorIndex, 0, screenHeight, 0, windowHeight);

                    if (xPosRemapped < 0)
                    {
                        xPosRemapped = 0;
                    }
                    else if (xPosRemapped > screenWidth)
                    {
                        xPosRemapped = screenWidth;
                    }
                    if (yPosRemapped < 0)
                    {
                        yPosRemapped = 0;
                    }
                    else if (yPosRemapped > screenHeight)
                    {
                        yPosRemapped = screenHeight;
                    }

                    Canvas.SetLeft(cursorImageIndex, xPosRemapped - (cursorSize / 2));
                    Canvas.SetTop(cursorImageIndex, yPosRemapped - (cursorSize / 2));
                }
                else if (cursorImageIndex.Opacity > 0)
                {
                    cursorImageIndex.Opacity -= 0.2;
                }

                if (showCursorThumb)
                {
                    if (cursorThumbDown)
                    {
                        cursorImageThumb.Source = bi1;
                    }
                    else
                    {
                        cursorImageThumb.Source = bi0;
                    }

                    if (cursorImageThumb.Opacity < 1)
                    {
                        cursorImageThumb.Opacity += 0.2;
                    }

                    int cursorSize = (int)(zCursorThumb * 5 * (float)windowWidth / (float)screenWidth);
                    if (cursorSize > 150)
                    {
                        cursorSize = 150;
                    }
                    else if (cursorSize < 50)
                    {
                        cursorSize = 50;
                    }

                    cursorImageThumb.Width = cursorImageThumb.Height = cursorSize;

                    int xPosRemapped = (int)map_val(xCursorThumb, 0, screenWidth, 0, windowWidth);
                    int yPosRemapped = (int)map_val(yCursorThumb, 0, screenHeight, 0, windowHeight);

                    if (xPosRemapped < 0)
                    {
                        xPosRemapped = 0;
                    }
                    else if (xPosRemapped > screenWidth)
                    {
                        xPosRemapped = screenWidth;
                    }
                    if (yPosRemapped < 0)
                    {
                        yPosRemapped = 0;
                    }
                    else if (yPosRemapped > screenHeight)
                    {
                        yPosRemapped = screenHeight;
                    }

                    Canvas.SetLeft(cursorImageThumb, xPosRemapped - (cursorSize / 2));
                    Canvas.SetTop(cursorImageThumb, yPosRemapped - (cursorSize / 2));
                }
                else if (cursorImageThumb.Opacity > 0)
                {
                    cursorImageThumb.Opacity -= 0.2;
                }

                cursorIndexDownOld = cursorIndexDown;
                cursorThumbDownOld = cursorThumbDown;

                xCursorThumbOld = xCursorThumb;
                yCursorThumbOld = yCursorThumb;
                zCursorThumbOld = zCursorThumb;

                xCursorIndexOld = xCursorIndex;
                yCursorIndexOld = yCursorIndex;
                zCursorIndexOld = zCursorIndex;
            };

            timer.Start();
        }