Retrieve number of mice

Hi all,

I’ve been working on an app that tracks mouse movements, but it goes bonkers when the number of mice is anything other that 1. I need to write cases for when no mouse is detected on the system (important for tablets) and for when more than one is detected on the system, but I can’t find a way to poll for the number of mice.

Does anyone know of a way?

Not a massive help, but here is some C code if you follow enough to translate it (and you are working in Windows)
Remember that on a PC, a mouse is only one input device that generates mouse events.
Trackpad, nipple on a laptop, and graphics tablet are all likely to show up here.

[code]
#include <windows.h>

#include <Hidsdi.h>
#include <SetupAPI.h>
#include <devguid.h>

#include <stdio.h>

#pragma comment(lib, “hid.lib”)
#pragma comment(lib, “setupapi.lib”)

int main(int argc, char ** argv)
{
GUID hid_guid;
GUID mouse_guid = GUID_DEVCLASS_MOUSE;
HDEVINFO hdevinfo;
SP_DEVICE_INTERFACE_DATA devinterface;
SP_DEVINFO_DATA devinfo;
BYTE devdetailbuffer[4096];
PSP_DEVICE_INTERFACE_DETAIL_DATA devdetail;
DWORD n;

HidD_GetHidGuid(&hid_guid);

hdevinfo = SetupDiGetClassDevs(&hid_guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);

if (hdevinfo == INVALID_HANDLE_VALUE)
{
    printf("SetupDiGetClassDevs: %u\

", GetLastError());
return 1;
}

for (n = 0;; n++)
{
    devinterface.cbSize = sizeof(devinterface);
    if (!SetupDiEnumDeviceInterfaces(hdevinfo, NULL, &hid_guid, n, &devinterface))
    {
        printf("SetupDiEnumDeviceInterfaces: %u\

", GetLastError());
break;
}
devdetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)devdetailbuffer;
devdetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
devinfo.cbSize = sizeof(devinfo);
if (!SetupDiGetDeviceInterfaceDetail(hdevinfo, &devinterface, devdetail, sizeof(devdetailbuffer), NULL, &devinfo))
{
printf("SetupDiGetDeviceInterfaceDetail: %u
", GetLastError());
break;
}
if (IsEqualGUID(&devinfo.ClassGuid, &mouse_guid))
{
// This is a mouse
printf("DevicePath: %ws
", devdetail->DevicePath);
}
}
return 0;
}[/code]