public TouchEventArgs(TouchEventArgs tea)
 {
     this.x = tea.x;
     this.y = tea.y;
     this.id = tea.id;
     this.mask = tea.mask;
     this.flags = tea.flags;
     this.time = tea.time;
     this.contactX = tea.contactX;
     this.contactY = tea.contactY;
     this.wparam = tea.wparam;
     this.lparam = tea.lparam;
 }
 private void DecodeTouch(IntPtr wparam, IntPtr lparam)
 {
     int cInputs = LoWord(wparam.ToInt32());
     if (cInputs == 0)
     {
         Win32.CloseTouchInputHandle(lparam);
     }
     else
     {
         TOUCHINPUT[] pInputs = new TOUCHINPUT[cInputs];
         if (!Win32.GetTouchInputInfo(lparam, cInputs, pInputs, this.mdTouchInputSize))
         {
             Win32.GetLastError();
         }
         else
         {
             for (int i = 0; i < cInputs; i++)
             {
                 TOUCHINPUT touchinput = pInputs[i];
                 EventHandler<TouchEventArgs> touchDown = null;
                 if ((touchinput.dwFlags & 2L) != 0L)
                 {
                     touchDown = this.TouchDown;
                 }
                 else if ((touchinput.dwFlags & 4L) != 0L)
                 {
                     touchDown = this.TouchUp;
                 }
                 else if ((touchinput.dwFlags & 1L) != 0L)
                 {
                     touchDown = this.TouchMove;
                 }
                 if (touchDown != null)
                 {
                     TouchEventArgs e = new TouchEventArgs();
                     e.contactX = touchinput.cxContact / 100;
                     e.contactY = touchinput.cyContact / 100;
                     e.id = touchinput.dwID;
                     e.x = (int) (((float) (touchinput.x / 100)) / this.scalingFactorX);
                     e.y = (int) (((float) (touchinput.y / 100)) / this.scalingFactorY);
                     e.time = touchinput.dwTime;
                     e.mask = touchinput.dwMask;
                     e.flags = touchinput.dwFlags;
                     touchDown(this, e);
                 }
             }
             Win32.CloseTouchInputHandle(lparam);
         }
     }
 }
Exemple #3
0
 private static void Hook_TouchDown(object sender, TouchHook.TouchEventArgs e)
 {
     throw new NotImplementedException();
 }
Exemple #4
0
 private void Hook_TouchDown(object sender, TouchHook.TouchEventArgs e)
 {
     //richTextBox1.AppendText($"clicked {e.x},{e.y}\n");
     richTextBox1.AppendText($"clicked\n");
 }
        /// <summary>
        /// Decodes and handles WM_TOUCH message
        /// Unpacks message arguments and invokes appropriate touch events.
        /// </summary>
        /// <param name="message">window message</param>
        private void DecodeTouch(IntPtr wparam, IntPtr lparam)
        {
            // More than one touchinput structure may be with each message, so an array is needed
            // to get all event information

            // Actual number of touch inputs
            int inputCount = LoWord(wparam.ToInt32());

            //just in case
            if (inputCount == 0)
            {
                Win32.CloseTouchInputHandle(lparam);
                return;
            }

            // Allocate the memory for the touch input structs
            TOUCHINPUT[] inputs;
            inputs = new TOUCHINPUT[inputCount];

            // Unpack message parameter into the array of TOUCHINPUT structures
            // Each one represents a message for one single contact
            if (!Win32.GetTouchInputInfo(lparam, inputCount, inputs, mdTouchInputSize))
            {
                // Get touch info failed
                Int32 lastError = Win32.GetLastError();

                Debug.Assert(false, "GetTouchInputInfo() failed error=0x", lastError.ToString("X"));

                return;
            }

            for (int i = 0; i < inputCount; ++i)
            {
                TOUCHINPUT touchInput = inputs[i];

                /*
                 * if ((touchInput.dwFlags & Win32.TOUCHEVENTF_MOVE) == 0)
                 * {
                 *  Console.Write(i.ToString() + ")x=" + touchInput.x.ToString());
                 *  Console.Write(", y=" + touchInput.y.ToString());
                 *  Console.Write(", Flags=0x" + touchInput.dwFlags.ToString("X"));
                 *  Console.Write(", Mask =0x" + touchInput.dwMask.ToString("X"));
                 *  Console.Write(", Time =0x" + touchInput.dwTime.ToString("X"));
                 *  Console.Write(", Info=0x" + touchInput.dwExtraInfo.ToString("X"));
                 *  Console.Write(", cx=0x" + touchInput.cxContact.ToString("X"));
                 *  Console.WriteLine(", cy=0x" + touchInput.cyContact.ToString("X"));
                 * }
                 */

                // Assign a handler to this message
                EventHandler <TouchEventArgs> handler = null;
                if ((touchInput.dwFlags & Win32.TOUCHEVENTF_DOWN) != 0)
                {
#if STRESS_TEST
                    Console.WriteLine("Touch Down:" + touchInput.dwID.ToString() + " wparam=" + wparam.ToString("X") + ", lparam=" + lparam.ToString("X"));
#endif
                    handler = TouchDown;
                }
                else if ((touchInput.dwFlags & Win32.TOUCHEVENTF_UP) != 0)
                {
#if STRESS_TEST
                    Console.WriteLine("Touch Up:" + touchInput.dwID.ToString() + " wparam=" + wparam.ToString("X") + ", lparam=" + lparam.ToString("X"));
#endif
                    handler = TouchUp;
                }
                else if ((touchInput.dwFlags & Win32.TOUCHEVENTF_MOVE) != 0)
                {
#if STRESS_TEST
                    //Console.WriteLine("Touch Move:" + touchInput.dwID.ToString() + " wparam=" + wparam.ToString("X") + ", lparam=" + lparam.ToString("X"));
#endif
                    handler = TouchMove;
                }

                if (handler != null)
                {
                    TouchEventArgs args = new TouchEventArgs();

                    // Convert message parameters into a touch event argument structure
                    // Convert to pixels and convert screen to client coordinates
                    // See [winuser.h] for:
                    //      #define TOUCH_COORD_TO_PIXEL(l)         ((l) / 100)
                    args.contactX = touchInput.cxContact / 100;
                    args.contactY = touchInput.cyContact / 100;
                    args.id       = touchInput.dwID;
                    // Touch coordinates are in absolute screen space, not bound to the client rectangle.
                    // These will have to be converted into client space after the event is captured.
                    args.x = (int)(touchInput.x / 100 / scalingFactorX);
                    args.y = (int)(touchInput.y / 100 / scalingFactorY);

                    args.time  = touchInput.dwTime;
                    args.mask  = touchInput.dwMask;
                    args.flags = touchInput.dwFlags;

                    handler(this, args);

#if STRESS_TEST
                    //record the event
                    if ((touchInput.dwFlags & Win32.TOUCHEVENTF_DOWN) != 0)
                    {
                        args.wparam = wparam;
                        args.lparam = lparam;

                        TouchEventArgs other = new TouchEventArgs(args);
                        TouchEventArgs down  = new TouchEventArgs(args);

                        string Message = "";

                        int foundID = 0;
                        int count   = touchEventArgsTrackList.Count;

                        //scan to see if this event exists
                        foreach (TouchEventArgs touchArgs in touchEventArgsTrackList)
                        {
                            if (touchArgs.id == args.id)
                            {
                                foundID++;
                                Message += args.id.ToString() + ',';
                            }
                        }

                        if (foundID > 0)
                        {
                            DialogResult result;
                            Message += '\n';
                            result   = MessageBox.Show("id count=" + foundID.ToString() + "\n"
                                                       + Message
                                                       ,
                                                       "Duplicate id's found",
                                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                        }

                        touchEventArgsTrackList.Add(other);
                        touchEventArgsTrackDownList.Add(down);
                    }

                    if ((touchInput.dwFlags & Win32.TOUCHEVENTF_UP) != 0)
                    {
                        //scan to see if this event has a matching down
                        foreach (TouchEventArgs touchArgs in touchEventArgsTrackList)
                        {
                            if (touchArgs.id == args.id)
                            {
                                touchEventArgsTrackList.Remove(touchArgs);
                                break;
                            }
                        }
                    }
#endif
                }
            }

            Win32.CloseTouchInputHandle(lparam);
        }