Skip to content

Commit

Permalink
Add proper usage and page labels
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Jun 14, 2024
1 parent 0e39c27 commit b26b9d8
Show file tree
Hide file tree
Showing 5 changed files with 432 additions and 16 deletions.
2 changes: 1 addition & 1 deletion BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 59
#define BUILD_NUMBER 60
26 changes: 14 additions & 12 deletions IDirectInputX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "dinputto8.h"
#include <hidusage.h>

HRESULT m_IDirectInputX::QueryInterface(REFIID riid, LPVOID FAR * ppvObj, DWORD DirectXVersion)
{
Expand Down Expand Up @@ -101,23 +102,24 @@ HRESULT m_IDirectInputX::EnumDevicesX(DWORD dwDevType, V lpCallback, LPVOID pvRe
ConvertDevSubTypeTo7(lpddi->dwDevType & 0xFF, (lpddi->dwDevType & 0xFF00) >> 8) << 8 | // Add converted sub type
dwConvertedDevType; // Add converted device type

if ((DI.dwDevType & DIDEVTYPE_DEVICE) && (DI.dwDevType & DIDEVTYPE_HID) && DI.wUsagePage == 0x01)
if ((DI.dwDevType & DIDEVTYPE_DEVICE) && (DI.dwDevType & DIDEVTYPE_HID))
{
// For usage see here: https://github.com/MysteriousJ/Joystick-Input-Examples?tab=readme-ov-file#hid
switch (DI.wUsage)
// Check if the device is a mouse
if (DI.wUsagePage == HID_USAGE_PAGE_GENERIC && DI.wUsage == HID_USAGE_GENERIC_MOUSE)
{
case 0x02: // Mouse
DI.dwDevType = (DI.dwDevType & ~DIDEVTYPE_DEVICE) | DIDEVTYPE_MOUSE;
break;
case 0x04: // Joystick
case 0x05: // Game pad
}
// Check if the device is a joystick or gamepad
else if (DI.wUsagePage == HID_USAGE_PAGE_GENERIC &&
(DI.wUsage == HID_USAGE_GENERIC_JOYSTICK || DI.wUsage == HID_USAGE_GENERIC_GAMEPAD))
{
DI.dwDevType = (DI.dwDevType & ~DIDEVTYPE_DEVICE) | DIDEVTYPE_JOYSTICK;
break;
case 0x06: // Keyboard
}
// Check if the device is a keyboard
else if ((DI.wUsagePage == HID_USAGE_PAGE_GENERIC && DI.wUsage == HID_USAGE_GENERIC_KEYBOARD) ||
DI.wUsagePage == HID_USAGE_PAGE_KEYBOARD)
{
DI.dwDevType = (DI.dwDevType & ~DIDEVTYPE_DEVICE) | DIDEVTYPE_KEYBOARD;
break;
default:
break;
}
}

Expand Down
9 changes: 9 additions & 0 deletions Include/winapifamily.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#define WINAPI_PARTITION_DESKTOP 0x00000001
#define WINAPI_FAMILY_DESKTOP_APP WINAPI_PARTITION_DESKTOP

// WINAPI_FAMILY is usually defined by the build system based on the target platform
#ifndef WINAPI_FAMILY
#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
#endif

#define WINAPI_FAMILY_PARTITION(Partition) ((WINAPI_FAMILY & Partition) == Partition)
Loading

0 comments on commit b26b9d8

Please sign in to comment.