Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recognize touch as MouseDown event

Tags:

c#

winforms

touch

I am building a puzzle game in C#, winforms for a touch screen.

I am able to handle touch events on mouse handlers, in fact, i did nothing at all, but it already recognizes my touches. However, there is an issue that i can't figure it out. The mouse_down, only happens when i move a bit my finger, and did not recognize the instant when i touch the screen.

Does anyone has already faced this problem? Should i implement some touch events recognition? If so, could you please point me some documentation or examples?

Many Thanks in advance

like image 889
Jorge Oliveira Avatar asked May 29 '14 18:05

Jorge Oliveira


People also ask

Does touch trigger MouseDown?

Because mobile browsers should also work with with web applications that were build for mouse devices, touch devices also fire classic mouse events like mousedown or click . When a user follows a link on a touch device, the following events will be fired in sequence: touchstart. touchend.

What is MouseDown event in C#?

Occurs when the mouse pointer is over the control and a mouse button is pressed. public: event System::Windows::Forms::MouseEventHandler ^ MouseDown; C# Copy.

Which of the following is a touch event in html5?

Touch events consist of three interfaces ( Touch , TouchEvent and TouchList ) and the following event types: touchstart - fired when a touch point is placed on the touch surface. touchmove - fired when a touch point is moved along the touch surface. touchend - fired when a touch point is removed from the touch surface.


1 Answers

Thanks @PiotrWolkowski

You were correct about the way i should follow... Some other issues appear, but i solved the initial problem overriding the WndProc as showed in the following:

protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case Win32.WM_POINTERDOWN:
            case Win32.WM_POINTERUP:
            case Win32.WM_POINTERUPDATE:
            case Win32.WM_POINTERCAPTURECHANGED:
                break;

            default:
                base.WndProc(ref m);
                return;
        }
        int pointerID = Win32.GET_POINTER_ID(m.WParam);
        Win32.POINTER_INFO pi = new Win32.POINTER_INFO();
        if (!Win32.GetPointerInfo(pointerID, ref pi))
        {
            Win32.CheckLastError();
        }
        Point pt = PointToClient(pi.PtPixelLocation.ToPoint());
        MouseEventArgs me = new MouseEventArgs(System.Windows.Forms.MouseButtons.Left, 1, pt.X, pt.Y, 0);
        switch (m.Msg)
        {
            case Win32.WM_POINTERDOWN:
                    Console.WriteLine("TOCOU" + pt);
                    (Parent as Jogo).Form1_MouseDown((this as object), me);
                break;

            case Win32.WM_POINTERUP:
                    Console.WriteLine("LEVANTOU");
                    (Parent as Jogo).Form1_MouseUp((this as object), me);
                break;

            case Win32.WM_POINTERUPDATE:
                    //Console.WriteLine("UPDATE");
                    (Parent as Jogo).Form1_MouseMove((this as object), me);
                break;
        }
    }

It was supported by an "Win32.cs" that can be downloaded here:

https://gist.github.com/RSchwoerer/bc5c04899c0510aefca24f088a79cebf

Hope this is helpful for you;)

like image 130
Jorge Oliveira Avatar answered Oct 06 '22 20:10

Jorge Oliveira