How to detect if there is a finger on the touchpad

234 Views Asked by At

I would like to ask a question about the touchpad. I am trying to make a program and i need to detect when a finger is on the touchpad. I do not want to detect the TAP. I would like to know if the touchpad touched.

I am trying to find a solution for this 2 weeks. I found a way to detect the TAP but i do not want this. I am reading from windows Touch Messages and everything i can find online. here. But no luck.

I am very gratefull if someone could guide me to make this work.

Thank you for your time,

Sorry if my english is bad.

1

There are 1 best solutions below

0
On

Ok,

My with Marko's answer since now i have this code.

#include <iostream>
#include <windows.h>
#include <winuser.h>

using namespace std;

LRESULT CALLBACK TestWndProc(HWND in_hWnd, UINT in_uMsg, WPARAM in_wParam, LPARAM in_lParam);


LRESULT CALLBACK TestWndProc(HWND in_hWnd, UINT in_uMsg, WPARAM in_wParam, LPARAM in_lParam)
{
    switch (in_uMsg)
    {
    case WM_TOUCH:
        cout << "WM_TOUCH";
        UINT cInputs = LOWORD(in_wParam);
        PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs];
        if (NULL != pInputs)
        {
            if (GetTouchInputInfo((HTOUCHINPUT)in_lParam,
                cInputs,
                pInputs,
                sizeof(TOUCHINPUT)))
            {
                for (int i = 0; i < static_cast<INT>(cInputs); i++) {
                    TOUCHINPUT ti = pInputs[i];
                }
                
                // process pInputs
                if (!CloseTouchInputHandle((HTOUCHINPUT)in_lParam))
                {
                    // error handling
                }
            }
            else
            {
                // GetLastError() and error handling
            }
            delete[] pInputs;
        }
        else
        {
            // error handling, presumably out of memory
        }

        

    }

    // default processing
    return DefWindowProc(in_hWnd, in_uMsg, in_wParam, in_lParam);
}

void main()
{
    MSG msg;
    BOOL bRet;
    while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
    {
        if (bRet == -1)
        {
            // handle the error and possibly exit
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
}

But i am afraid i had messed up all of this in my mind. I would like to print a message to the console that says "Finger on touchpad" when the finger is on touchpad.

Now i am trying to find how to get the TOUCH_UP and TOUCH_DOWN message.