【问题标题】:How to detect if there is a finger on the touchpad如何检测触摸板上是否有手指
【发布时间】:2020-12-03 13:53:56
【问题描述】:

我想问一个关于触摸板的问题。我正在尝试制作一个程序,我需要检测手指何时在触摸板上。我不想检测 TAP。我想知道触摸板是否被触摸。

我正在努力为这 2 周寻找解决方案。我找到了一种检测 TAP 的方法,但我不想要这个。 我正在阅读 Windows Touch Messages 和我可以在网上找到的所有内容。 here。 但没有运气。

如果有人能指导我完成这项工作,我将不胜感激。

感谢您的宝贵时间,

对不起,如果我的英语不好。

【问题讨论】:

  • 我浏览了文档:在WM_MESSAGE 上调用GetTouchInputInfo,其结果将存储在pInputs 中是否有触地,如here 所述。 dwFlags 包含 onUponDown 信息。
  • 显示您尝试过的代码。

标签: windows windows-10 touchpad c++


【解决方案1】:

好的,

我同意 Marko 的回答,因为现在我有了这个代码。

#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);
        }
    }
}

但恐怕我把这一切都搞砸了。 当手指在触摸板上时,我想向控制台打印一条消息,显示“手指在触摸板上”。

现在我正在尝试找到如何获取 TOUCH_UP 和 TOUCH_DOWN 消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    相关资源
    最近更新 更多