Ejemplo n.º 1
0
        /// <summary>
        /// Decoces the message.
        /// </summary>
        /// <param name="m">The Message.</param>
        private void DecodeMessage(Message m)
        {
            int inputCount = m.WParam.ToInt32();

            var touchInput = new TouchInput[inputCount];

            if (!TouchInterops.GetTouchInputInfo(m.LParam, inputCount, touchInput, Marshal.SizeOf(touchInput)))
            {
                _logger.Warn("Error while extracting TouchInputInfo.");
                return;
            }

            for (int i = 0; i < inputCount; i++)
            {
                TouchInput touchInfo = touchInput[i];
                var        touchMode = TouchMode.Down;

                if ((touchInfo.dwFlags & (int)TouchFlags.TOUCHEVENTF_DOWN) != 0)
                {
                    touchMode = TouchMode.Down;
                }
                else if ((touchInfo.dwFlags & (int)TouchFlags.TOUCHEVENTF_UP) != 0)
                {
                    touchMode = TouchMode.Up;
                }
                else if ((touchInfo.dwFlags & (int)TouchFlags.TOUCHEVENTF_MOVE) != 0)
                {
                    touchMode = TouchMode.Move;
                }


                var touch = new Input.Touch(touchInfo.dwID,
                                            new Vector2(touchInfo.cxContact / 100f, touchInfo.cyContact / 100f),
                                            new Vector2(touchInfo.x / 100f, touchInfo.y / 100f), new DateTime(0, 0, 0, 0, 0, 0, touchInfo.dwTime),
                                            touchMode);

                _touches.Add(touch);


                if (!TouchInterops.CloseTouchInputHandle(m.LParam))
                {
                    _logger.Warn("Unable to close TouchInputHandle.");
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the input.
        /// </summary>
        public void Initialize()
        {
            IntPtr handle = SGL.Components.Get <RenderTarget>().Handle;


            if (!TouchInterops.RegisterTouchWindow(handle, 0))
            {
                throw new InvalidOperationException("Unable to register TouchWindow.");
            }

            IsAvailable = true;

            var msgFilter = new MessageFilter(handle)
            {
                Filter = TouchInterops.WM_TOUCH
            };

            msgFilter.MessageArrived += MessageArrived;
            _handle = handle;
        }