如何在 Windows 上检索手写笔压力信息?

发布于 2024-07-10 21:36:49 字数 250 浏览 5 评论 0原文

有谁知道在 Windows 上获取平板电脑/手写笔压力信息的合理方法吗?

可以使用 ::GetMessageExtraInfo 区分手写笔和鼠标,但除此之外您无法获取更多信息。 我还在 Wacom 站点的一个偏僻角落发现了 WinTab API,但据我所知,它不是 Windows 的一部分,并且具有与消息队列完全不同的事件/消息系统。

鉴于我想要的只是最基本的压力信息,肯定有一个标准的 Win32/COM API,有人知道它可能是什么吗?

Is anyone aware of a sane way to get tablet/stylus pressure information on Windows?

It's possible to distinguish stylus from mouse with ::GetMessageExtraInfo, but you can't get any more information beyond that. I also found the WinTab API in a out of the way corner of the Wacom site, but that's not part of windows as far as i can tell, and has a completely distinct event/messaging system from the message queue.

Given all I want is the most basic pressure information surely there is a standard Win32/COM API, is anyone aware of what it might be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

月下客 2024-07-17 21:36:49

当前的方法是处理 WM_POINTERnnn 消息。
请注意,这适用于 Win 8 及更高版本。

请注意,您将收到触摸和笔的这些消息,因此您需要知道指针类型才能测试笔。 WNDPROC 收到的 WM_POINTERnnnn 消息(例如 WM_POINTERUPDATE 和其他消息)的 WPARAM 包含指针 id,您需要该指针 id 来请求更多信息。 根据经验,我发现 WM_POINTERUPDATE 会产生包含压力数据的信息,而如果指针标志指示向下/向上,则没有压力信息。

const WORD wid = GET_POINTERID_WPARAM(wParam);
POINTER_INFO piTemp = {NULL};
GetPointerInfo(wid, &piTemp);
if (piTemp.pointerType == PT_PEN
{
    UINT32 entries = 0;
    UINT32 pointers = 0;

    GetPointerFramePenInfoHistory(wid, &entries, &pointers, NULL); // how many
    // TODO, allocate space needed for the info, process the data in a loop to retrieve it, test pointerInfo.pointerFlags for down/up/update.

}

一旦你知道你正在处理笔,你就可以从 POINTER_PEN_INFO 结构中获取压力信息。

这与处理触摸类似,尽管对于触摸,您需要手势识别和惯性。 有一个 Microsoft 示例说明了如何使用这些函数。

这是构建演讲的一部分:
https://channel9.msdn.com/Events/Build/2013/4-022

The current way to do this is to handle WM_POINTERnnn msgs.
Note this is for Win 8 and later.

Note you will get these msgs for touch AND pen, so you'll need to know the pointerType in order to test for pen. The WPARAM received by a WNDPROC for WM_POINTERnnnn msgs such a WM_POINTERUPDATE and other msgs contains the pointer id which you will need in order to request more info. Empirically I found that WM_POINTERUPDATE results in info that contains pressure data whereas if the pointer flags indicate down/up there is no pressure info.

const WORD wid = GET_POINTERID_WPARAM(wParam);
POINTER_INFO piTemp = {NULL};
GetPointerInfo(wid, &piTemp);
if (piTemp.pointerType == PT_PEN
{
    UINT32 entries = 0;
    UINT32 pointers = 0;

    GetPointerFramePenInfoHistory(wid, &entries, &pointers, NULL); // how many
    // TODO, allocate space needed for the info, process the data in a loop to retrieve it, test pointerInfo.pointerFlags for down/up/update.

}

Once you know you are dealing with pen, you can get the pressure info from the POINTER_PEN_INFO struct.

This is similar to handling touch although for touch you'd want gesture recognition and inertia. There is a Microsoft sample illustrating using these functions.

It's part of a Build talk:
https://channel9.msdn.com/Events/Build/2013/4-022

那请放手 2024-07-17 21:36:49

您需要使用 Tablet PC Pen/Ink API。 API 的 COM 版本位于 InkObj.dll 中。 以下是文档的起点: http://msdn.microsoft.com/ en-us/library/ms700664.aspx

如果我没记错的话,InkObj.dll 在 Windows XP SP2 和所有更高版本的 Windows 客户端操作系统上都可用,无论计算机是否是平板电脑。

You need to use the Tablet PC Pen/Ink API. The COM version of the API lives in InkObj.dll. Here is a starting point for documentation: http://msdn.microsoft.com/en-us/library/ms700664.aspx

If I remember correctly, InkObj.dll is available on Windows XP SP2 and all later Windows client OSes, regardless of whether the machine is a Tablet PC.

乄_柒ぐ汐 2024-07-17 21:36:49

更新:
自从我最初提供这个答案以来已经有很多年了,但是 wintab 已经成为事实上的标准,并且 Ntrig 或多或少地折叠起来,最终构建了一个包装器以允许通过此数字转换器访问 wintab API。< br>
(http://www.tabletpcbuzz.com /showthread.php?37547-N-trig-Posts-WinTAB-Support-Driver)

这是一个相当晚的回复,但最近我和我的妻子购买了一台 Dell XT 平板电脑,因为它事实证明,实际上使用的是 NTrig,这是一套利用 Ink 的界面,Ink 是随 Windows XP 平板电脑版本、SP 2 及其后所有版本一起提供的公认的新 Windows API。

许多 Wacom 平板电脑和其他平板电脑都使用 Wintab API,该 API 目前尚未开放,也未真正允许使用。 据我所知,维护它的人非常乐意起诉。

因此,这取决于您使用的平板电脑类型以及为其安装的驱动程序。 在我看来,您应该使用 Ink,因为它提供(或至少通过 NTrig 和 Windows 7 将提供)多点触控功能,并且很可能成为平板电脑界面的新标准。 但截至目前,NTrig 设备尚未将其压力和角度信息转换为常见的基于 Wintab 的应用程序,例如 Photoshop 或 Corel Painter。 这些应用程序往往需要至少对 Microsoft 平板电脑 API 的一些支持才能正常运行。

UPDATE:
It's been a number of years since I initially provided this answer, but wintab has become the de facto standard, and Ntrig more or less folded, eventually building a wrapper to allow for the wintab API to be accessed via this digitizer.
(http://www.tabletpcbuzz.com/showthread.php?37547-N-trig-Posts-WinTAB-Support-Driver)

This is a pretty late response, but recently my wife and I purchased a Dell XT tablet PC, which as it turns out actually uses NTrig, a suite of interfaces that utilize Ink, the accepted new windows API that shipped with Windows XP Tablet edition, then SP 2 and all versions thereafter.

A lot of Wacom tablets and others use the Wintab API, which is not currently open nor really permitted to use. From what I hear the folks who maintain it are pretty sue-happy.

So it depends on what type of tablet you're using, and the drivers you have installed for it. In my biased opinion, you should work with Ink, as it provides (or at least through NTrig and Windows 7 WILL provide) multi-touch capability and will likely be the new standard for tablet interfaces. But as of now, NTrig devices do not translate their pressure and angle information to common Wintab-based applications, such as Photoshop or Corel Painter. The applications tend to require at least some support for Microsoft's Tablet API in order to function properly.

旧情别恋 2024-07-17 21:36:49

如果使用 UWP Windows 运行时 那么就非常简单了。 PointerEventArgs事件似乎拥有所有必要的数据。

修改核心应用 (C++/WinRT) 模板项目片段:

void OnPointerMoved(IInspectable const &, PointerEventArgs const &args)
{
    if (m_selected)
    {
        float2 const point = args.CurrentPoint().Position();

        m_selected.Offset(
            {
                point.x + m_offset.x,
                point.y + m_offset.y,
                0.0f
            });

        // (new!) Change sprite color based on pen pressure and tilt
        auto sprite = m_selected.as<SpriteVisual>();
        
        auto const props = args.CurrentPoint().Properties();
        auto const pressure = props.Pressure();
        auto const orientation = props.Orientation() / 360.0f;
        auto const tiltx = (props.XTilt() + 90) / 180.0f;
        auto const tilty = (props.YTilt() + 90) / 180.0f;

        Compositor compositor = m_visuals.Compositor();
        sprite.Brush(compositor.CreateColorBrush({
            (uint8_t)(pressure * 0xFF),
            (uint8_t)(tiltx * 0xFF),
            (uint8_t)(tilty * 0xFF),
            (uint8_t)(orientation * 0xFF)
            }));
    }
}

类似的代码可能适用于 C#、JavaScript 等。

If using UWP Windows Runtime then it's quite straightforward. The PointerEventArgs event seems to have all necessary data.

Modified Core App (C++/WinRT) template project snippet from Visual Studio 2019:

void OnPointerMoved(IInspectable const &, PointerEventArgs const &args)
{
    if (m_selected)
    {
        float2 const point = args.CurrentPoint().Position();

        m_selected.Offset(
            {
                point.x + m_offset.x,
                point.y + m_offset.y,
                0.0f
            });

        // (new!) Change sprite color based on pen pressure and tilt
        auto sprite = m_selected.as<SpriteVisual>();
        
        auto const props = args.CurrentPoint().Properties();
        auto const pressure = props.Pressure();
        auto const orientation = props.Orientation() / 360.0f;
        auto const tiltx = (props.XTilt() + 90) / 180.0f;
        auto const tilty = (props.YTilt() + 90) / 180.0f;

        Compositor compositor = m_visuals.Compositor();
        sprite.Brush(compositor.CreateColorBrush({
            (uint8_t)(pressure * 0xFF),
            (uint8_t)(tiltx * 0xFF),
            (uint8_t)(tilty * 0xFF),
            (uint8_t)(orientation * 0xFF)
            }));
    }
}

Similar code will likely work in C#, JavaScript, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文