Screen touch recognition such as Mousedown

Asked

Viewed 74 times

1

I’m developing a game (Puzzle) in C# Winforms, to run on a touch screen. The mapping of touch events to mouse events already occurs by default, and I didn’t have to do anything to make it happen. However, the mouse_down, just occurs when I move my finger a little bit, and it doesn’t occur in the precise moment where I touch the screen.

Why does this happen?
I must implement some kind of touch event recognition?

  • 1

    When you touch the screen, does the mouse cursor appear immediately at the point you touched? Or does it only appear when you move your finger? If the second case occurs, I think the problem lies in how that particular screen works. Otherwise I hope you get a good answer to your question.

  • I am currently testing on a Sony Vaio Tap 20, and when I use the touch instead of the mouse, the usual cursor disappears and is replaced by a circle. However, this circle appears at the moment when the touch occurs, and it is not necessary to make any kind of movement.

1 answer

0


Other problems have arisen however, such as the overlap and difficulty of distinguishing between touch or mouse events, but the problem above solved with 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;
        }
    }

I used a "Win32.Cs" class that can be downloaded here:

https://dl.dropboxusercontent.com/u/4311953/Win32.cs

I hope it will be useful ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.