3

Background

I am trying to get the touch coordinates from precision touchpads with C++ in Win10 with the program running in background.


Research

Rawinput can get data in background.

I can get the data with these usage id and pages from microsoft :

Member  Description                         Page    ID      Mandatory/Optional
X       X coordinate of contact position    0x01    0x30    Mandatory for T Optional for C
Y       Y coordinate of contact position    0x01    0x31    Mandatory for T Optional for C

I can put the two of them together with HIDP_functions, from this answer.


Code

case WM_INPUT: {
    UINT dwSize;
    GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
    LPBYTE lpb = new BYTE[dwSize];
    if (lpb == NULL) {
        return 0;
    }
    RAWINPUT* raw = (RAWINPUT*)lpb;
    GetRawInputDeviceInfo(raw->header.hDevice, RIDI_PREPARSEDDATA, NULL, &dwSize);
    PHIDP_PREPARSED_DATA preparsedData = (PHIDP_PREPARSED_DATA)HeapAlloc(GetProcessHeap(), 0, dwSize);
    GetRawInputDeviceInfo(raw->header.hDevice, RIDI_PREPARSEDDATA, preparsedData, &dwSize); 

    HIDP_CAPS caps;
    HidP_GetCaps(preparsedData, &caps);
    USHORT capsLength = caps.NumberInputValueCaps;
    PHIDP_VALUE_CAPS valueCaps = (PHIDP_VALUE_CAPS)HeapAlloc(GetProcessHeap(), 0, capsLength*sizeof(HIDP_VALUE_CAPS));

    HidP_GetValueCaps(HidP_Input, valueCaps, &capsLength, preparsedData);
    for (int i=0; i < capsLength; i++) {
        CHAR value;
        USHORT valuelength = valueCaps[i].BitSize * valueCaps[i].ReportCount;
        HidP_GetUsageValueArray (HidP_Input, valueCaps[i].UsagePage, 0, valueCaps[i].NotRange.Usage, &value, valuelength, preparsedData, (PCHAR)raw->data.hid.bRawData, raw->data.hid.dwSizeHid);
        std::cout << valueCaps[i].UsagePage << "  " << valueCaps[i].NotRange.Usage <<std::endl;
        std::cout << value << std::endl;

        switch(valueCaps[i].NotRange.Usage) {
            case 0x30:    // X-axis
                std::cout << "X: " << value << std::endl;
                break;

            case 0x31:    // Y-axis
                std::cout << "y: " << value << std::endl;
                break;
        }
    }

}

Problem

I compiled the code and touch my touchpad, but all the outputs are:

0  0
³

Have I done anything wrong? Does anyone have any idea?

Benny10033
  • 31
  • 3
  • Forgot to add: I want to get the data with the program in background. So I can't use Windows Touch api. – Benny10033 Oct 29 '17 at 21:55
  • Precision TouchPad lacks API right now, vote here to let Microsoft know we need it: https://aka.ms/Uun1l5 – m93a Jan 05 '18 at 18:48
  • I need to extract [X, Y] the same way, but for my touch screen monitor. – Xdg Feb 26 '19 at 18:57

2 Answers2

0

A packet of minimal Contact ID, x, y, Contact, Scan may contain multiple Contact ID, x, y triplets for multiple points and then must be used valueCaps[i].LinkCollection from valueCaps[] array which increases from 1 for up to five points.

HidP_GetUsageValue
(
    HidP_Input, 
    valueCaps[i].UsagePage, 
    valueCaps[i].LinkCollection, //** !!!!!
    valueCaps[i].NotRange.Usage, 
    &value, 
    preparsedData, 
    (PCHAR)raw->data.hid.bRawData, 
    raw->data.hid.dwSizeHid
);

Coordinates are in array if valueCaps[i].UsagePage = 1 and valueCaps[i].NotRange.Usage = 0x30 (x), valueCaps[i].NotRange.Usage = 0x30 (y)

Very important are xLogicalMin, yLogicalMin, xLogicalMax, yLogicalMax in valueCaps[i] array

    xLogicalMin = valueCaps[i].LogicalMin;
    xLogicalMax = valueCaps[i].LogicalMax;
    xPhysicalMin = valueCaps[i].PhysicalMin;
    xPhysicalMax = valueCaps[i].PhysicalMax;

All allocated spaces must be correct released !!!!!

Pressing оп perimeter points of touchpad for initiate multiple functions, or cells of grid on touchpad as on ASUS NumberPad also with limited functions of capacitive and active pen, one finger flicks, moving along four sides of touchpad for scrolling / scale, moving cursor with one finger and click, press, press plus move, double click, click plus press second finger. Two finger operations count increased at finger space near or far possible with coordinates. With coordinates, times in "Scan" and contacts in "Contact" all possible complex gestures on touchpad are accessible.

-1

Call of Your Program

HidP_GetUsageValueArray (HidP_Input, valueCaps[i].UsagePage, 0, valueCaps[i].NotRange.Usage, &value, valuelength, preparsedData, (PCHAR)raw->data.hid.bRawData, raw->data.hid.dwSizeHid);

returns HIDP_STATUS_NOT_VALUE_ARRAY = 0xc011000b

In Array valueCaps[] on my notebook with PTP are valueCaps[i].UsagePage = 1 and valueCaps[i].NotRange.Usage = 0x30 / 0x31. You can use simple

HidP_GetUsageValue ( HidP_Input, valueCaps[i].UsagePage, 0, valueCaps[i].NotRange.Usage, &value, preparsedData, (PCHAR)raw->data.hid.bRawData, raw->data.hid.dwSizeHid );

with 1 / 30h, 1 / 31h

corresponding to

_Must_inspect_result_ NTSTATUS __stdcall HidP_GetUsageValue( In HIDP_REPORT_TYPE ReportType, In USAGE UsagePage, _In_opt_ USHORT LinkCollection, In USAGE Usage, Out PULONG UsageValue, In PHIDP_PREPARSED_DATA PreparsedData, _In_reads_bytes_(ReportLength) PCHAR Report, In ULONG ReportLength );

and value ( UsageValue ) must be LONG !!!!!.

First value at WM_INPUT comes with UsagePage 0x0D Usage 0x51

Contact ID Uniquely identifies the contact within a given frame 0x0D 0x51 Mandatory

  • Constants for HID API are in header file hidusage.h and input.inf ( HIDClass ) in system directory "windows\inf" Coordinate and contact info may be used for create new flicks and gestures for touchpad e.g. rotation. – Alexander Alexander Jul 08 '18 at 11:02
  • In UWP there are Windows.​Devices.​Human​Interface​Device namespace and Hid​Device class – Alexander Alexander Jul 11 '18 at 03:55
  • Touch in different places of Touchpad may initiate multiple commands – Alexander Alexander Jul 25 '18 at 11:19
  • The coordinates are within valueCaps[i].LogicalMin and valueCaps[i].LogicalMax if valueCaps[i].NotRange.Usage = 0x30 and 0x31 – Alexander Alexander Jul 31 '18 at 05:47
  • At this processing new for touchpad press function is also accessible. – Alexander Alexander Jul 31 '18 at 06:43
  • HeapAlloc function needs HeapFree in the sample. – Alexander Alexander Aug 02 '18 at 05:15
  • Notebook Touchpad Touch Actions, processed with WM_INPUT - 1 Finger Touch, 2 Finger Touch, 1 Finger Touch next 1 Finger Touch, 2 Finger Touch next 1 Finger Touch may be combined with Active Stylus Click or contactless Active Stylus move, detected also with WM_INPUT processing for expand Active Stylus capabilities for simple, fast and easy user interactions. – Alexander Alexander Dec 31 '18 at 11:53
  • Comparing the change coordinate of the touchpad touch point and screen coordinates of the cursor allows you to specify additional movement of the cursor in the application, for example, for coverage of the entire screen by continuous touching and moving on the touchpad. – Alexander Alexander May 11 '21 at 09:15