1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| BOOL ParseInputInfo(HRAWINPUT lParam) { UINT uSize = 0; UINT uRet = GetRawInputData( lParam, RID_INPUT, NULL, &uSize, sizeof(RAWINPUTHEADER)); if (uRet != 0) return FALSE; PRAWINPUT pRawInput = (PRAWINPUT)malloc(uSize); if (!pRawInput) return FALSE; ZeroMemory(pRawInput, uSize); uRet = GetRawInputData( lParam, RID_INPUT, pRawInput, &uSize, sizeof(RAWINPUTHEADER)); if (uRet != uSize) return FALSE; uSize = 0; uRet = GetRawInputDeviceInfoW( pRawInput->header.hDevice, RIDI_PREPARSEDDATA, NULL, &uSize); if (uRet != 0) return FALSE; PHIDP_PREPARSED_DATA pPreparsedData = (PHIDP_PREPARSED_DATA)malloc(uSize); if (!pPreparsedData) return FALSE; ZeroMemory(pPreparsedData, uSize); uRet = GetRawInputDeviceInfoW( pRawInput->header.hDevice, RIDI_PREPARSEDDATA, pPreparsedData, &uSize); if (uRet != uSize) return FALSE; HIDP_CAPS stCaps = { 0 }; NTSTATUS ntStatus = HidP_GetCaps(pPreparsedData, &stCaps); if (ntStatus != HIDP_STATUS_SUCCESS) return FALSE; ULONG uDataSize = stCaps.NumberInputDataIndices * sizeof(HIDP_DATA); PHIDP_DATA pDataList = (PHIDP_DATA)malloc(uDataSize); if (!pDataList) return FALSE; ZeroMemory(pDataList, uDataSize); ULONG uDataNum = stCaps.NumberInputDataIndices; ntStatus = HidP_GetData( HidP_Input, pDataList, &uDataNum, pPreparsedData, (PCHAR)pRawInput->data.hid.bRawData, pRawInput->data.hid.dwSizeHid); if (ntStatus != HIDP_STATUS_SUCCESS) return FALSE; uSize = stCaps.NumberInputButtonCaps * sizeof(HIDP_BUTTON_CAPS); PHIDP_BUTTON_CAPS pButtonCaps = (PHIDP_BUTTON_CAPS)malloc(uSize); if (!pButtonCaps) return FALSE; ZeroMemory(pButtonCaps, uSize); ntStatus = HidP_GetButtonCaps( HidP_Input, pButtonCaps, &stCaps.NumberInputButtonCaps, pPreparsedData); if (ntStatus != HIDP_STATUS_SUCCESS) return FALSE; for (DWORD i = 0; i < stCaps.NumberInputButtonCaps; i++) { BOOL isBtnData = FALSE; for (DWORD j = 0; j < uDataNum; j++) { if (pDataList[j].DataIndex == pButtonCaps[i].NotRange.DataIndex) { isBtnData = pDataList[j].On; break; } } if (pButtonCaps[i].UsagePage == 0x0D && pButtonCaps[i].NotRange.Usage == 0x47) { } } uSize = stCaps.NumberInputValueCaps * sizeof(HIDP_VALUE_CAPS); PHIDP_VALUE_CAPS pValueCaps = (PHIDP_VALUE_CAPS)malloc(uSize); if (!pValueCaps) return FALSE; ZeroMemory(pValueCaps, uSize); ntStatus = HidP_GetValueCaps( HidP_Input, pValueCaps, &stCaps.NumberInputValueCaps, pPreparsedData); if (ntStatus != HIDP_STATUS_SUCCESS) return FALSE; for (DWORD i = 0; i < stCaps.NumberInputValueCaps; i++) { ULONG uValueData = 0; for (DWORD j = 0; j < uDataNum; j++) { if (pDataList[j].DataIndex == pValueCaps[i].NotRange.DataIndex) { uValueData = pDataList[j].RawValue; break; } } if (pValueCaps[i].UsagePage == 0x01 && pValueCaps[i].NotRange.Usage == 0x30) { LONG nXMax = pValueCaps[i].LogicalMax; } } free(pDataList); free(pButtonCaps); free(pValueCaps); free(pPreparsedData); free(pRawInput); return TRUE; }
|