private TouchEvent CreateTouchEvent(TouchEventArgs args, TouchEvent.TouchEventAction action)
 {
     return new TouchEvent
     {
         Action = action,
         Id = args.Id,
         TranslatedPosition = new Vector2(args.Location.X, args.Location.Y),
         NonTranslatedPosition = new Vector2(args.Location.X, args.Location.Y),
         TimeStamp = DateTime.Now
     };
 }
 private void OnHandlerOnTouchUp(object sender, TouchEventArgs touchEventArgs)
 {
     _queuedEvents.Add(CreateTouchEvent(touchEventArgs, TouchEvent.TouchEventAction.Up));
 }
 private void OnHandlerOnTouchDown(object sender, TouchEventArgs args)
 {
     _queuedEvents.Add(CreateTouchEvent(args, TouchEvent.TouchEventAction.Down));
 }
Exemple #4
0
        /// <summary>
        /// Decode the message and create a collection of event arguments
        /// </summary>
        /// <remarks>
        /// One Windows message can result a group of events
        /// </remarks>
        /// <returns>An enumerator of thr resuting events</returns>
        /// <param name="hWnd">the WndProc hWnd</param>
        /// <param name="msg">the WndProc msg</param>
        /// <param name="wParam">the WndProc wParam</param>
        /// <param name="lParam">the WndProc lParam</param>
        private IEnumerable<TouchEventArgs> DecodeMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, float dpiX, float dpiY)
        {
            // More than one touchinput may be associated with a touch message,
            // so an array is needed to get all event information.
            int inputCount = User32.LoWord(wParam.ToInt32()); // Number of touch inputs, actual per-contact messages

            TOUCHINPUT[] inputs; // Array of TOUCHINPUT structures
            inputs = new TOUCHINPUT[inputCount]; // Allocate the storage for the parameters of the per-contact messages
            try
            {
                // Unpack message parameters into the array of TOUCHINPUT structures, each
                // representing a message for one single contact.
                if (!User32.GetTouchInputInfo(lParam, inputCount, inputs, Marshal.SizeOf(inputs[0])))
                {
                    // Get touch info failed.
                    throw new Exception("Error calling GetTouchInputInfo API");
                }

                // For each contact, dispatch the message to the appropriate message
                // handler.
                // Note that for WM_TOUCHDOWN you can get down & move notifications
                // and for WM_TOUCHUP you can get up & move notifications
                // WM_TOUCHMOVE will only contain move notifications
                // and up & down notifications will never come in the same message
                for (int i = 0; i < inputCount; i++)
                {
                    TouchEventArgs touchEventArgs = new TouchEventArgs(HWndWrapper, dpiX, dpiY, ref inputs[i]);
                    yield return touchEventArgs;
                }
            }
            finally
            {
                User32.CloseTouchInputHandle(lParam);
            }
        }