Raw Input Device informations

I was working with a small project where we had the task to identify raw input devices attached to the system. We also needed to retrieve the attached raw input device informations in detail. I found few online articles and APIs on MSDN which proved to be very useful in completing the task assigned to me.

In this article I am going to explain and demonstrate the usage of these RAW Input APIs. As a additional reference I strongly recommend the MSDN article( RAW INPUT ). In the example chosen, I have used two Win32 APIs to enumerate the attached raw input devices, each device name and device informations. The following section describes two Win32 APIs briefly.

UINT GetRawInputDeviceList( PRAWINPUTDEVICELIST pRawInputDeviceList,
                            PUINT puiNumDevices,
                            UINT cbSize);

This function is used for enumeration of raw input devices. For full description please follow MSDN article ( GetRawInputDeviceList ).

UINT GetRawInputDeviceInfo( HANDLE hDevice,
                            UINT uiCommand,
                            LPVOID pData,
                            PUINT pcbSize);

To get detailed information about the attached devices, use the  GetRawInputDeviceInfo function. The following demo code snippet is the implemenation details to get attached raw input devices name and information:

// HIDDeviceCheck.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "HIDDeviceCheck.h"

#ifdef _DEBUG
#define new DEBUG_NEW

// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
   int nRetCode = 0;

   // initialize MFC and print and error on failure
   if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
      // TODO: change error code to suit your needs
      _tprintf(_T("Fatal Error: MFC initialization failed\n"));
      nRetCode = 1;
      // TODO: code your application's behavior here.

      UINT nDevices;
      PRAWINPUTDEVICELIST pRawInputDeviceList;
      if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) 
         cout << "Errors..." << endl;
         return 1;

      if ((pRawInputDeviceList = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * nDevices)) == NULL) 
         cout << "Initialization failed..." << endl;
         return 1;

      int nNoOfDevices = 0;
      if ((nNoOfDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) == ((UINT) - 1)) 
         // Error
         return 1;

      RID_DEVICE_INFO rdi;
      rdi.cbSize = sizeof(RID_DEVICE_INFO);

      for(int i = 0; i < nNoOfDevices; i++)
         UINT size = 256;
         TCHAR tBuffer[256] = {0};
         if(GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, tBuffer, &size) < 0)
            // Error in reading device name

         // cout << "Device Name: " << tBuffer << endl;
         _tprintf(L"Device Name: %s\n", tBuffer);

         UINT cbSize = rdi.cbSize;
         if(GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &rdi, &cbSize) < 0)
            // Error in reading information

         if(rdi.dwType == RIM_TYPEMOUSE)
            cout << "ID for Mouse:" << rdi.mouse.dwId << endl;
            cout << "Number of Buttons:" << rdi.mouse.dwNumberOfButtons << endl;
            cout << "Sample rate(Number of data points):" << rdi.mouse.dwSampleRate << endl;
            cout << "**************************" << endl;

         if(rdi.dwType == RIM_TYPEKEYBOARD)
            cout << "Keyboard Mode:" << rdi.keyboard.dwKeyboardMode << endl;
            cout << "Number of function keys:" << rdi.keyboard.dwNumberOfFunctionKeys << endl;
            cout << "Number of indicators:" << rdi.keyboard.dwNumberOfIndicators << endl;
            cout << "Number of keys total: " << rdi.keyboard.dwNumberOfKeysTotal << endl;
            cout << "Type of the keyboard: " << rdi.keyboard.dwType << endl;
            cout << "Subtype of the keyboard: " << rdi.keyboard.dwSubType << endl;
            cout << "***********************" << endl;

         if(rdi.dwType == RIM_TYPEHID)
            cout << "Vendor Id:" << rdi.hid.dwVendorId << endl;
            cout << "Product Id:" << rdi.hid.dwProductId << endl;
            cout << "Version No:" << rdi.hid.dwVersionNumber << endl;
            cout << "Usage for the device: " << rdi.hid.usUsage << endl;
            cout << "Usage Page for the device: " << rdi.hid.usUsagePage << endl;
            cout << "***********************" << endl;


   return nRetCode;

The snap shot of the output looks like the picture below:

About the Author

Mufti Mohammed

Small-Talk and Small-Programming working together. My Blog


  • Doubt on Device Name

    Posted by Punavgowda on 10/15/2015 02:21am

    How to differentiate between Barcode scanner name and keyboard name for following list+ "\\?\Root#RDP_KBD#0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}" "\\?\HID#VID_05F9&PID_221C#7&301561c3;&0&0000;#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}"

  • Doubt on duplicate info

    Posted by RAMESH on 05/26/2015 11:48pm

    Could you please tell me why it showing 2 mouse and 2 key board info

  • Minimum Requirements

    Posted by Brad Jones on 03/17/2009 11:19am

    Comment from a Codeguru reviewer: The minimum operating systems requirement for "Raw Inputs" is Windows XP

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Essential Insights for Successful Cloud Migration and Management Whether you're planning your cloud migration strategy or already in the cloud, making accurate cloud decisions requires a deep analytical approach. This paper discusses the main objectives to achieve, top questions to ask, and the analytics you need at each stage of your cloud journey. You'll learn: How to identify which cloud provider will provide the best cost and performance benefits for your organization How to determine which applications …

  • Featuring Art Schoeller, VP and Principal Analyst, at Forrester Research Live Event Date: November 9, 2016 @ 10 AM PT / 1 PM ET Being "proactive" with your customers is not enough to survive in the market today. The truth is, organizations that understand how to engage customers on their preferred channels will create contextual, and relevant experiences for customers. Plus, they will see the financial impact of nurturing long-term customer loyalty. Join our guest speaker Art Schoeller, VP and Principal …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date