void WindowsGamepadService::ScanForRawInputDevices() { if (!mHID) { return; } UINT numDevices; if (GetRawInputDeviceList(nullptr, &numDevices, sizeof(RAWINPUTDEVICELIST)) == kRawInputError) { return; } nsTArray<RAWINPUTDEVICELIST> devices(numDevices); devices.SetLength(numDevices); if (GetRawInputDeviceList(devices.Elements(), &numDevices, sizeof(RAWINPUTDEVICELIST)) == kRawInputError) { return; } for (unsigned i = 0; i < devices.Length(); i++) { if (devices[i].dwType == RIM_TYPEHID) { GetRawGamepad(devices[i].hDevice); } } }
bool nxRawInputDevice::Enumerate(std::vector<nxRawInputDevice>&vcRawDevices) { nxRawInputDevice objDevice; UINT uNumDev; vcRawDevices.clear(); try { if (GetRawInputDeviceList(NULL,&uNumDev,sizeof(RAWINPUTDEVICELIST)) != 0) nxThrow("Error retrieving number of raw input devices."); std::vector<RAWINPUTDEVICELIST> rdl(uNumDev); if (uNumDev && (GetRawInputDeviceList(&rdl[0],&uNumDev,sizeof(RAWINPUTDEVICELIST)) == (UINT)-1)) nxThrow("Error retrieving list of raw input devices."); for (std::vector<RAWINPUTDEVICELIST>::iterator it=rdl.begin();it!=rdl.end();++it) { objDevice.hDevice = it->hDevice; objDevice.dwType = it->dwType; if (objDevice.GetInformation()) vcRawDevices.push_back(objDevice); objDevice.Clear(); } } catch (const std::exception&e) { nxLog << e.what() << std::endl; return false; } return true; }
std::vector<logicalaccess::KeyboardEntry> InputDevice::getDeviceList() { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# begins."); std::vector<logicalaccess::KeyboardEntry> deviceList; std::string root1 = "\\\\?\\Root"; std::string root2 = "\\??\\Root"; UINT nDevices; //PRAWINPUTDEVICELIST pRawInputDeviceList; UINT errorCode = GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)); if (errorCode == 0 || errorCode == ERROR_INSUFFICIENT_BUFFER) { std::vector<RAWINPUTDEVICELIST> newlist(nDevices); nDevices = GetRawInputDeviceList(&newlist[0], &nDevices, sizeof(RAWINPUTDEVICELIST)); if (nDevices > 0 ) { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# {%u} device(s) detected.", nDevices); for (std::vector<RAWINPUTDEVICELIST>::const_iterator it = newlist.begin(); it != newlist.end(); ++it) { if ((*it).dwType == RIM_TYPEKEYBOARD) { logicalaccess::KeyboardEntry entry; memset(&entry, 0x00, sizeof(entry)); entry.handle = (unsigned long long) (*it).hDevice; UINT nSize = 0; GetRawInputDeviceInfo((HANDLE)entry.handle, RIDI_DEVICENAME, NULL, &nSize); if (nSize > 0) { nSize = sizeof(entry.name); errorCode = GetRawInputDeviceInfo((HANDLE)entry.handle, RIDI_DEVICENAME, entry.name, &nSize); } // Skip Terminal Services and Remote Desktop generic keyboards if (memcmp(entry.name, root1.c_str(), root1.size()) != 0 && memcmp(entry.name, root2.c_str(), root2.size()) != 0) { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# Keyboard device found {%s}!", entry.name); deviceList.push_back(entry); } } } } else { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# No devices detected."); } } else { islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# Error GetRawInputDeviceList {%d}!", errorCode); } islogkbdlib::KbdLogs::getInstance()->LogEvent("#getDeviceList# return."); return deviceList; }
/** * Checks if the 3D Mouse is connected * @return returns 1 if the device is connected, 0 if the device is not connected, -1 if there is an error. */ int isDeviceConnected() { UINT nDevices; PRAWINPUTDEVICELIST pRawInputDeviceList; if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { return -1; } if(nDevices<1) { return 0; } pRawInputDeviceList = new RAWINPUTDEVICELIST[nDevices]; if (GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)) == (UINT) -1) { return -1; } bool found=false; for(int i=0;i<nDevices;i++) { RID_DEVICE_INFO rdi; rdi.cbSize= sizeof(rdi); UINT cbSize = sizeof(rdi); if(GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &rdi, &cbSize) > 0) { if (rdi.dwType == RIM_TYPEHID || rdi.hid.dwVendorId == LOGITECH_VENDOR_ID) { found=true; break; } } } delete[] pRawInputDeviceList; if(found) { return 1; } else { return 0; } }
static void list_input_devices() { UINT num_devices; PRAWINPUTDEVICELIST pRawInputDeviceList; if (GetRawInputDeviceList(NULL, &num_devices, sizeof(RAWINPUTDEVICELIST)) != 0) { fs_ml_fatal("GetRawInputDeviceList (count devices) failed "); } if ((pRawInputDeviceList = malloc(sizeof(RAWINPUTDEVICELIST) * num_devices)) == NULL) { fs_ml_fatal_malloc(); } if (GetRawInputDeviceList(pRawInputDeviceList, &num_devices, sizeof(RAWINPUTDEVICELIST)) == -1) { fs_ml_fatal("GetRawInputDeviceList (get devices) failed "); } for (int i = 0; i < num_devices; i++) { fs_log("device index: %d\n", i); fs_log("device type: %d\n", pRawInputDeviceList[i].dwType); char device_name[1024]; unsigned int data_size = 1023; if (GetRawInputDeviceInfo( pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, &device_name, &data_size) == -1) { fs_ml_error("GetRawInputDeviceInfo (RIDI_DEVICENAME) failed"); continue; } fs_log(" name: %s\n", device_name); RID_DEVICE_INFO device_info; device_info.cbSize = sizeof(RID_DEVICE_INFO); data_size = sizeof(RID_DEVICE_INFO); if (GetRawInputDeviceInfo( pRawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &device_info, &data_size) == -1) { fs_ml_error("GetRawInputDeviceInfo failed"); continue; } //fs_log(" type: %d\n", device_info.dwType); } free(pRawInputDeviceList); }
// adapted from SDL2, works a lot better than the MSDN version bool joystick_windows::is_xinput_device(const GUID *p_guid) { static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; if (p_guid == &IID_ValveStreamingGamepad || p_guid == &IID_X360WiredGamepad || p_guid == &IID_X360WirelessGamepad) return true; PRAWINPUTDEVICELIST dev_list = NULL; unsigned int dev_list_count = 0; if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { return false; } dev_list = (PRAWINPUTDEVICELIST) malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count); if (!dev_list) return false; if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { free(dev_list); return false; } for (int i = 0; i < dev_list_count; i++) { RID_DEVICE_INFO rdi; char dev_name[128]; UINT rdiSize = sizeof(rdi); UINT nameSize = sizeof(dev_name); rdi.cbSize = rdiSize; if ( (dev_list[i].dwType == RIM_TYPEHID) && (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1) && (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == (LONG)p_guid->Data1) && (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) && (strstr(dev_name, "IG_") != NULL)) { free(dev_list); return true; } } free(dev_list); return false; }
std::vector<RAWINPUTDEVICELIST> rawinput_device_list(){ UINT _num_devices; UINT _result; if(0 != GetRawInputDeviceList(0, &_num_devices, sizeof(RAWINPUTDEVICELIST))){ std::cerr << "0 != GetRawInputDeviceList(0, &num_devices, sizeof(RAWINPUTDEVICELIST))" << std::endl; return std::vector<RAWINPUTDEVICELIST>(); } std::vector<RAWINPUTDEVICELIST> device_list(_num_devices); _result = GetRawInputDeviceList(&device_list[0], &_num_devices, sizeof(RAWINPUTDEVICELIST)); if(-1 == _result){ std::cerr << "-1 == _result" << std::endl; return std::vector<RAWINPUTDEVICELIST>(); } device_list.resize(_result); return device_list; }
//============================================================================= void ListDevices () { UINT numDevices; PRAWINPUTDEVICELIST pRawInputDeviceList; if (GetRawInputDeviceList(NULL, &numDevices, sizeof(*pRawInputDeviceList)) != 0) { return; } if ((pRawInputDeviceList = (PRAWINPUTDEVICELIST)malloc(sizeof(*pRawInputDeviceList) * numDevices)) == NULL) { return; } if (GetRawInputDeviceList(pRawInputDeviceList, &numDevices, sizeof(RAWINPUTDEVICELIST)) == UINT(-1)) { free(pRawInputDeviceList); return; } for (unsigned i = 0; i < numDevices; ++i) { RID_DEVICE_INFO devInfo; UINT devInfoSize = sizeof(devInfo); memset(&devInfo, 0, sizeof(devInfo)); UINT f = GetRawInputDeviceInfo( pRawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &devInfo, &devInfoSize ); TCHAR buf2[512]; swprintf_s( buf2, L"HID device: vendor=0x%X product=0x%X\n", devInfo.hid.dwVendorId, devInfo.hid.dwProductId ); OutputDebugString(buf2); } free(pRawInputDeviceList); }
void Input::enumerate_devices() { _mice.clear(); UINT numDevices; GetRawInputDeviceList(NULL, &numDevices, sizeof(RAWINPUTDEVICELIST)); if (numDevices == 0) return; std::vector<RAWINPUTDEVICELIST> deviceList(numDevices); GetRawInputDeviceList(&deviceList[0], &numDevices, sizeof(RAWINPUTDEVICELIST)); std::vector<wchar_t> deviceNameData; std::wstring deviceName; for (UINT i = 0; i < numDevices; ++i) { const RAWINPUTDEVICELIST& device = deviceList[i]; if (device.dwType == RIM_TYPEMOUSE) { _mice.push_back(std::make_shared<Mouse>(device.hDevice)); } else if (device.dwType == RIM_TYPEKEYBOARD) { _keyboards.push_back(std::make_shared<Keyboard>(device.hDevice)); } else { std::cout << "HID device" << std::endl; } } }
void Server::InitRawInput() { RAWINPUTDEVICE Rid[10]; // allocate storage for 10 device UINT nDevices; PRAWINPUTDEVICELIST pRawInputDeviceList; if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { return; } pRawInputDeviceList = (RAWINPUTDEVICELIST *)malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)); // after the job, free the RAWINPUTDEVICELIST free(pRawInputDeviceList); // add Game pad Rid[0].usUsagePage = 0x01; Rid[0].usUsage = 0x05; Rid[0].dwFlags = 0; Rid[0].hwndTarget = 0; // add Keyboard Rid[1].usUsagePage = 0x01; Rid[1].usUsage = 0x06; Rid[1].dwFlags = RIDEV_NOLEGACY; // adds HID keyboard and also ignores legacy keyboard messages Rid[1].hwndTarget = 0; // add Mouse // Rid[2].usUsagePage = 0x01; // Rid[2].usUsage = 0x02; // Rid[2].dwFlags = RIDEV_NOLEGACY; // adds HID mouse and also ignores legacy mouse messages // Rid[2].hwndTarget = NULL; if (RegisterRawInputDevices(Rid, 2, sizeof (Rid [0])) == FALSE) { printf("RawInput init failed:\n"); //registration failed. } return ; }
int _tmain(int argc, _TCHAR* argv[]) { BOOL b; UINT size = 0, i; RAWINPUTDEVICELIST *pRawInputDeviceList; b = GetRawInputDeviceList(NULL, &size, sizeof(RAWINPUTDEVICELIST)); printf("b ==> %d, size ==> %d\n", b, size); pRawInputDeviceList = (RAWINPUTDEVICELIST *)malloc(sizeof(RAWINPUTDEVICELIST)* size); b = GetRawInputDeviceList(pRawInputDeviceList, &size, sizeof(RAWINPUTDEVICELIST)); printf("b ==> %d, size ==> %d\n", b, size); for (i = 0; i < size; ++i) { WCHAR buffer[MAX_PATH + 1]; printf("device.type ==> 0x%x\n", pRawInputDeviceList[i].dwType); printf("device.handle ==> 0x%p\n", pRawInputDeviceList[i].hDevice); UINT BufferSize = ARRAYSIZE(buffer); UINT retval = GetRawInputDeviceInfoW(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, &buffer[0], &BufferSize); printf("retval ==> %d\n", retval); printf("buffer ==> %ws\n", buffer); RID_DEVICE_INFO DeviceInfo = { 0 }; BufferSize = sizeof(DeviceInfo); retval = GetRawInputDeviceInfoW(pRawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &DeviceInfo, &BufferSize); printf("Device info.dwType ==> 0x%x\n", DeviceInfo.dwType); if (DeviceInfo.dwType == RIM_TYPEHID) { printf("usage page ==> 0x%x, usage ==> 0x%x\n", DeviceInfo.hid.usUsagePage, DeviceInfo.hid.usUsage); } } return 0; }
bool RawInputSystem::init() { initWinKeyTable(); #ifndef _EDITOR RAWINPUTDEVICE device; device.usUsagePage = 0x01; device.usUsage = 0x02; device.dwFlags = 0; device.hwndTarget = NULL; RegisterRawInputDevices(&device, 1, sizeof(device)); DWORD error = GetLastError(); UINT nDevices; PRAWINPUTDEVICELIST pRawInputDeviceList = PRAWINPUTDEVICELIST(); GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)); LOG_INFO("Total of " << nDevices << " input devices detected!"); free(pRawInputDeviceList); #endif return true; }
/* Based on SDL2's implementation. */ static bool guid_is_xinput_device(const GUID* product_guid) { unsigned i, num_raw_devs = 0; PRAWINPUTDEVICELIST raw_devs = NULL; /* Check for well known XInput device GUIDs, * thereby removing the need for the IG_ check. * This lets us skip RAWINPUT for popular devices. * * Also, we need to do this for the Valve Streaming Gamepad * because it's virtualized and doesn't show up in the device list. */ for (i = 0; i < ARRAY_SIZE(common_xinput_guids); ++i) { if (memcmp(product_guid, &common_xinput_guids[i], sizeof(GUID)) == 0) return true; } /* Go through RAWINPUT (WinXP and later) to find HID devices. */ if (!raw_devs) { if ((GetRawInputDeviceList(NULL, &num_raw_devs, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) || (!num_raw_devs)) return false; raw_devs = (PRAWINPUTDEVICELIST) malloc(sizeof(RAWINPUTDEVICELIST) * num_raw_devs); if (!raw_devs) return false; if (GetRawInputDeviceList(raw_devs, &num_raw_devs, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) { free(raw_devs); raw_devs = NULL; return false; } } for (i = 0; i < num_raw_devs; i++) { RID_DEVICE_INFO rdi; char devName[128] = {0}; UINT rdiSize = sizeof(rdi); UINT nameSize = sizeof(devName); rdi.cbSize = sizeof (rdi); if ((raw_devs[i].dwType == RIM_TYPEHID) && (GetRawInputDeviceInfoA(raw_devs[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != ((UINT)-1)) && (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == ((LONG)product_guid->Data1)) && (GetRawInputDeviceInfoA(raw_devs[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != ((UINT)-1)) && (strstr(devName, "IG_") != NULL) ) { free(raw_devs); raw_devs = NULL; return true; } } free(raw_devs); raw_devs = NULL; return false; }
/* We can't really tell what device is being used for XInput, but we can guess and we'll be correct for the case where only one device is connected. */ static void GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *pVersion) { #ifndef __WINRT__ /* TODO: remove this ifndef __WINRT__ block, but only after integrating with UWP/WinRT's HID API */ PRAWINPUTDEVICELIST devices = NULL; UINT i, j, device_count = 0; if ((GetRawInputDeviceList(NULL, &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) || (!device_count)) { return; /* oh well. */ } devices = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * device_count); if (devices == NULL) { return; } if (GetRawInputDeviceList(devices, &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) { SDL_free(devices); return; /* oh well. */ } for (i = 0; i < device_count; i++) { RID_DEVICE_INFO rdi; char devName[128]; UINT rdiSize = sizeof(rdi); UINT nameSize = SDL_arraysize(devName); rdi.cbSize = sizeof(rdi); if ((devices[i].dwType == RIM_TYPEHID) && (GetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != ((UINT)-1)) && (GetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != ((UINT)-1)) && (SDL_strstr(devName, "IG_") != NULL)) { SDL_bool found = SDL_FALSE; for (j = 0; j < SDL_arraysize(s_arrXInputDevicePath); ++j) { if (j == userid) { continue; } if (!s_arrXInputDevicePath[j]) { continue; } if (SDL_strcmp(devName, s_arrXInputDevicePath[j]) == 0) { found = SDL_TRUE; break; } } if (found) { /* We already have this device in our XInput device list */ continue; } /* We don't actually know if this is the right device for this * userid, but we'll record it so we'll at least be consistent * when the raw device list changes. */ *pVID = (Uint16)rdi.hid.dwVendorId; *pPID = (Uint16)rdi.hid.dwProductId; *pVersion = (Uint16)rdi.hid.dwVersionNumber; if (s_arrXInputDevicePath[userid]) { SDL_free(s_arrXInputDevicePath[userid]); } s_arrXInputDevicePath[userid] = SDL_strdup(devName); break; } } SDL_free(devices); #endif /* ifndef __WINRT__ */ }
static SDL_bool SDL_IsXInputDevice(const GUID* pGuidProductFromDirectInput) { static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_XOneWiredGamepad = { MAKELONG(0x045E, 0x02FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_XOneWirelessGamepad = { MAKELONG(0x045E, 0x02DD), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_XOneNewWirelessGamepad = { MAKELONG(0x045E, 0x02D1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_XOneSWirelessGamepad = { MAKELONG(0x045E, 0x02EA), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_XOneSBluetoothGamepad = { MAKELONG(0x045E, 0x02E0), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_XOneEliteWirelessGamepad = { MAKELONG(0x045E, 0x02E3), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static const GUID *s_XInputProductGUID[] = { &IID_ValveStreamingGamepad, &IID_X360WiredGamepad, /* Microsoft's wired X360 controller for Windows. */ &IID_X360WirelessGamepad, /* Microsoft's wireless X360 controller for Windows. */ &IID_XOneWiredGamepad, /* Microsoft's wired Xbox One controller for Windows. */ &IID_XOneWirelessGamepad, /* Microsoft's wireless Xbox One controller for Windows. */ &IID_XOneNewWirelessGamepad, /* Microsoft's updated wireless Xbox One controller (w/ 3.5 mm jack) for Windows. */ &IID_XOneSWirelessGamepad, /* Microsoft's wireless Xbox One S controller for Windows. */ &IID_XOneSBluetoothGamepad, /* Microsoft's Bluetooth Xbox One S controller for Windows. */ &IID_XOneEliteWirelessGamepad /* Microsoft's wireless Xbox One Elite controller for Windows. */ }; size_t iDevice; UINT i; if (!SDL_XINPUT_Enabled()) { return SDL_FALSE; } /* Check for well known XInput device GUIDs */ /* This lets us skip RAWINPUT for popular devices. Also, we need to do this for the Valve Streaming Gamepad because it's virtualized and doesn't show up in the device list. */ for (iDevice = 0; iDevice < SDL_arraysize(s_XInputProductGUID); ++iDevice) { if (SDL_memcmp(pGuidProductFromDirectInput, s_XInputProductGUID[iDevice], sizeof(GUID)) == 0) { return SDL_TRUE; } } /* Go through RAWINPUT (WinXP and later) to find HID devices. */ /* Cache this if we end up using it. */ if (SDL_RawDevList == NULL) { if ((GetRawInputDeviceList(NULL, &SDL_RawDevListCount, sizeof(RAWINPUTDEVICELIST)) == -1) || (!SDL_RawDevListCount)) { return SDL_FALSE; /* oh well. */ } SDL_RawDevList = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * SDL_RawDevListCount); if (SDL_RawDevList == NULL) { SDL_OutOfMemory(); return SDL_FALSE; } if (GetRawInputDeviceList(SDL_RawDevList, &SDL_RawDevListCount, sizeof(RAWINPUTDEVICELIST)) == -1) { SDL_free(SDL_RawDevList); SDL_RawDevList = NULL; return SDL_FALSE; /* oh well. */ } } for (i = 0; i < SDL_RawDevListCount; i++) { RID_DEVICE_INFO rdi; char devName[128]; UINT rdiSize = sizeof(rdi); UINT nameSize = SDL_arraysize(devName); rdi.cbSize = sizeof(rdi); if ((SDL_RawDevList[i].dwType == RIM_TYPEHID) && (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != ((UINT)-1)) && (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == ((LONG)pGuidProductFromDirectInput->Data1)) && (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != ((UINT)-1)) && (SDL_strstr(devName, "IG_") != NULL)) { return SDL_TRUE; } } return SDL_FALSE; }
void GetRawInputDevice(bool is_mame_game) { UINT nDevices; PRAWINPUTDEVICELIST pRawInputDeviceList; char output[256]; if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { ga_error("GetRawInputDeviceList failed.\n"); exit(-1); } if ((pRawInputDeviceList = (PRAWINPUTDEVICELIST) malloc(sizeof(RAWINPUTDEVICELIST) * nDevices)) == NULL) { ga_error("Memory allocation for RawInputDeviceList failed.\n"); exit(-1); } nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)); if (nDevices <= 0) { ga_error("GetRawInputDeviceList failed.\n"); exit(-1); } ga_error("[raw input device] number of devices: %d\n", nDevices); int device_i = 0; //#define SHOW_DEVICE_MSG int j; RID_DEVICE_INFO rdi; rdi.cbSize = sizeof(RID_DEVICE_INFO); for (j = 0; j < nDevices; j++) { UINT nBufferSize = 256; char tBuffer[256] = {0}; if (GetRawInputDeviceInfo(pRawInputDeviceList[j].hDevice, RIDI_DEVICENAME, tBuffer, &nBufferSize) < 0) { ga_error("[device %d] Unable to get device name\n", j); continue; } #ifdef SHOW_DEVICE_MSG ga_error("[device %d] device name: %s\n", j, tBuffer); #endif // UINT cbSize = rdi.cbSize; if (GetRawInputDeviceInfo(pRawInputDeviceList[j].hDevice, RIDI_DEVICEINFO, &rdi, &cbSize) < 0) { ga_error("[device %d] Unable to get device info\n", j); continue; } if (rdi.dwType == RIM_TYPEMOUSE) { #ifdef SHOW_DEVICE_MSG ga_error("[device %d][Mouse] id: %ld, number of buttons: %ld, sample rate: %ld\n", j, rdi.mouse.dwId, rdi.mouse.dwNumberOfButtons, rdi.mouse.dwSampleRate); #endif } else if (rdi.dwType == RIM_TYPEKEYBOARD) { #ifdef SHOW_DEVICE_MSG ga_error("[device %d][keyboard] mode %ld, number of function keys: %ld, indicators: %ld, keys total: %ld, type: %ld, subtype: %ld\n", j, rdi.keyboard.dwKeyboardMode, rdi.keyboard.dwNumberOfFunctionKeys, rdi.keyboard.dwNumberOfIndicators, rdi.keyboard.dwNumberOfKeysTotal, rdi.keyboard.dwType, rdi.keyboard.dwSubType); #endif //char *str_loc; if (strstr(tBuffer, "HID") != NULL) { device_i = j; tmpRawKeyDevice = pRawInputDeviceList[j].hDevice; ga_error("[raw input device] keyboard device is found!\n"); break; } } else { #ifdef SHOW_DEVICE_MSG ga_error("[device %d][hid] vender id: %ld, product id: %ld, version no: %ld, usage: %ld, usage page: %ld\n", j, rdi.hid.dwVendorId, rdi.hid.dwProductId, rdi.hid.dwVersionNumber, rdi.hid.usUsage, rdi.hid.usUsagePage); #endif } } //int device_i = 0; if (is_mame_game) { ga_error("[RAW INPUT] GetRawInputDevice: MAME device!!"); //device_i = 3; } //RAWINPUTDEVICELIST *device = &pRawInputDeviceList[device_i]; //tmpRawKeyDevice = device->hDevice; snprintf(output, sizeof(output), "[GetRawInputDevice] keyDevice: %u (%d)", tmpRawKeyDevice, device_i); OutputDebugString(output); free(pRawInputDeviceList); return; }
static void EnumerateDevices() { // Enumerate devices int i; UINT numDevicesFound = 64; RAWINPUTDEVICELIST allDevices[64]; RID_DEVICE_INFO deviceInfo; WCHAR s[256]; WCHAR name[256]; UINT retVal; UINT sizeInfo; ZeroMemory(&(allDevices[0]), sizeof(allDevices)); numDevicesFound = GetRawInputDeviceList(&(allDevices[0]), &numDevicesFound, sizeof(RAWINPUTDEVICELIST)); for (i = 0; i < (int)numDevicesFound; ++i) { if ((allDevices[i].dwType == RIM_TYPEHID) || (allDevices[i].dwType == RIM_TYPEMOUSE) || (allDevices[i].dwType == RIM_TYPEKEYBOARD)) { ZeroMemory(&deviceInfo, sizeof(deviceInfo)); sizeInfo = sizeof(deviceInfo); retVal = GetRawInputDeviceInfo(allDevices[i].hDevice, RIDI_DEVICEINFO, &deviceInfo, &sizeInfo); UINT bufferSize = 0; retVal = GetRawInputDeviceInfo(allDevices[i].hDevice, RIDI_DEVICENAME, NULL, &bufferSize); if (retVal < 0) { _snwprintf( &(s[0]), 256, L"Device %d, Vendor=%X, Product=%X, Version=%d, UsagePage=%d, Usage=%d: FAILED TO GET DEVICE NAME!\n", i, deviceInfo.hid.dwVendorId, deviceInfo.hid.dwProductId, deviceInfo.hid.dwVersionNumber, deviceInfo.hid.usUsagePage, deviceInfo.hid.usUsage, &(name[0])); continue; } WCHAR* wcDeviceName = new WCHAR[bufferSize + 1]; retVal = GetRawInputDeviceInfo(allDevices[i].hDevice, RIDI_DEVICENAME, wcDeviceName, &bufferSize); if (retVal < 0) { _snwprintf( &(s[0]), 256, L"Device %d, Vendor=%X, Product=%X, Version=%d, UsagePage=%d, Usage=%d: FAILED TO GET DEVICE NAME!\n", i, deviceInfo.hid.dwVendorId, deviceInfo.hid.dwProductId, deviceInfo.hid.dwVersionNumber, deviceInfo.hid.usUsagePage, deviceInfo.hid.usUsage, &(name[0])); continue; } _snwprintf( &(s[0]), 256, L"\n\nDevice %d:\nVendor=%X\nProduct=%X\nVersion=%d\nUsagePage=%d\nUsage=%d\nName=%32S\n\n", i, deviceInfo.hid.dwVendorId, deviceInfo.hid.dwProductId, deviceInfo.hid.dwVersionNumber, deviceInfo.hid.usUsagePage, deviceInfo.hid.usUsage, &(wcDeviceName[0])); IwDebugTraceLinePrintf("360pad: %d, %d", deviceInfo.hid.dwVendorId, deviceInfo.hid.dwProductId); delete[] wcDeviceName; } } }
BOOL init_raw_mouse(BOOL in_include_sys_mouse, BOOL in_include_rdp_mouse, BOOL in_include_individual_mice, HWND hwnd) { // "0" to exclude, "1" to include int nInputDevices, i, j; PRAWINPUTDEVICELIST pRawInputDeviceList; int currentmouse = 0; int nSize; char *psName; char buffer[80]; excluded_sysmouse_devices_count = 0; nraw_mouse_count = 0; include_sys_mouse = in_include_sys_mouse; include_rdp_mouse = in_include_rdp_mouse; include_individual_mice = in_include_individual_mice; // 1st call to GetRawInputDeviceList: Pass NULL to get the number of devices. if (GetRawInputDeviceList(NULL, (PUINT) &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { fprintf(stderr, "ERROR: Unable to count raw input devices.\n"); return 0; } // Allocate the array to hold the DeviceList if ((pRawInputDeviceList = (PRAWINPUTDEVICELIST) malloc(sizeof(RAWINPUTDEVICELIST) * nInputDevices)) == NULL) { fprintf(stderr, "ERROR: Unable to allocate memory for raw input device list.\n"); return 0; } // 2nd call to GetRawInputDeviceList: Pass the pointer to our DeviceList and GetRawInputDeviceList() will fill the array if ( GetRawInputDeviceList(pRawInputDeviceList, (PUINT)&nInputDevices, sizeof(RAWINPUTDEVICELIST)) == -1) { fprintf(stderr, "ERROR: Unable to get raw input device list.\n"); return 0; } // Loop through all devices and count the mice for (i = 0; i < nInputDevices; i++) { if (pRawInputDeviceList[i].dwType == RIM_TYPEMOUSE ||pRawInputDeviceList[i].dwType == RIM_TYPEHID) { /* Get the device name and use it to determine if it's the RDP Terminal Services virtual device. */ // 1st call to GetRawInputDeviceInfo: Pass NULL to get the size of the device name if (GetRawInputDeviceInfo (pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, NULL, (PUINT) &nSize) != 0) { fprintf(stderr, "ERROR: Unable to get size of raw input device name.\n"); return 0; } // Allocate the array to hold the name if ((psName = (char *)malloc(sizeof(TCHAR) * nSize)) == NULL) { fprintf(stderr, "ERROR: Unable to allocate memory for device name.\n"); return 0; } // 2nd call to GetRawInputDeviceInfo: Pass our pointer to get the device name if ((int)GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, psName,(PUINT) &nSize) < 0) { fprintf(stderr, "ERROR: Unable to get raw input device name.\n"); return 0; } // Count this mouse for allocation if it's not an RDP mouse or if we want to include the rdp mouse if (is_rm_rdp_mouse(psName)) { if (include_rdp_mouse) nraw_mouse_count++; } else { // It's an ordinary mouse nraw_mouse_count++; if (!include_individual_mice) excluded_sysmouse_devices_count++; // Don't count this in the final nraw_mouse_count value } } } if (include_sys_mouse) nraw_mouse_count++; // Allocate the array for the raw mice if ((raw_mice = (PRAW_MOUSE)malloc(sizeof(RAW_MOUSE) * nraw_mouse_count)) == NULL) { fprintf(stderr, "ERROR: Unable to allocate memory for raw input mice.\n"); return 0; } // Define the sys mouse if (include_sys_mouse) { raw_mice[RAW_SYS_MOUSE].device_handle = 0; raw_mice[RAW_SYS_MOUSE].x = 0; raw_mice[RAW_SYS_MOUSE].y = 0; raw_mice[RAW_SYS_MOUSE].z = 0; raw_mice[RAW_SYS_MOUSE].is_absolute = 1; raw_mice[RAW_SYS_MOUSE].is_virtual_desktop = 0; //raw_mice[RAW_SYS_MOUSE].ID currentmouse++; } // Loop through all devices and set the device handles and initialize the mouse values for (i = 0; i < nInputDevices; i++) { if (pRawInputDeviceList[i].dwType == RIM_TYPEMOUSE ||pRawInputDeviceList[i].dwType == RIM_TYPEHID) { // 1st call to GetRawInputDeviceInfo: Pass NULL to get the size of the device name if (GetRawInputDeviceInfo (pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, NULL,(PUINT) &raw_mice[currentmouse].nSize) != 0) { fprintf(stderr, "ERROR: Unable to get size of raw input device name (2).\n"); return 0; } // Allocate the array to hold the name if ((raw_mice[currentmouse].psname = (char *)malloc(sizeof(TCHAR) * raw_mice[currentmouse].nSize)) == NULL) { fprintf(stderr, "ERROR: Unable to allocate memory for raw input device name (2).\n"); return 0; } // 2nd call to GetRawInputDeviceInfo: Pass our pointer to get the device name if ((int) GetRawInputDeviceInfo (pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, raw_mice[currentmouse].psname,(PUINT) &raw_mice[currentmouse].nSize) < 0) { fprintf(stderr, "ERROR: Unable to get raw input device name (2).\n"); return 0; } // Add this mouse to the array if it's not an RDPMouse or if we wish to include the RDP mouse if ((!is_rm_rdp_mouse(psName)) || include_rdp_mouse ) { raw_mice[currentmouse].device_handle = pRawInputDeviceList[i].hDevice; raw_mice[currentmouse].x = 0; raw_mice[currentmouse].y = 0; raw_mice[currentmouse].z = 0; raw_mice[currentmouse].is_absolute = 1; raw_mice[currentmouse].is_virtual_desktop = 0; currentmouse++; } } } // free the RAWINPUTDEVICELIST free(pRawInputDeviceList); for (i = 0; i < nraw_mouse_count; i++) { for (j = 0; j < MAX_RAW_MOUSE_BUTTONS; j++) { raw_mice[i].buttonpressed[j] = 0; // Create the name for this button sprintf(buffer, "Button %i", j); raw_mice[i].button_name[j] = (char *)malloc(strlen(buffer) + 1); sprintf(raw_mice[i].button_name[j], "%s", buffer); } } nraw_mouse_count -= excluded_sysmouse_devices_count; // finally, register to recieve raw input WM_INPUT messages if (!register_raw_mouse(hwnd)) { fprintf(stderr, "ERROR: Unable to register raw input (2).\n"); return 0; } return 1; }
static BOOL RegisterForRawInputs() { BOOL result = FALSE; PRAWINPUTDEVICELIST pRawInputDeviceList = NULL; do { BYTE data[2048]; UINT dataSize; UINT nDevices; TCHAR vidStr[10]; RAWINPUTDEVICE rawInputDevice; if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) < 0) { printf("GetRawInputDeviceList failed to get device count. Error code 0x%08X.\n", GetLastError()); break; } pRawInputDeviceList = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); if (NULL == pRawInputDeviceList) { printf("Malloc failed for pRawInputDeviceList.\n"); break; } nDevices = GetRawInputDeviceList(pRawInputDeviceList, (PUINT)&nDevices, sizeof(RAWINPUTDEVICELIST)); if (nDevices < 0) { printf("GetRawInputDeviceList failed to get device list. Error code 0x%08X.\n", GetLastError()); break; } _stprintf_s(vidStr, sizeof(vidStr) / sizeof(TCHAR), _T("%04X"), HARDWARE_VID); for (UINT i = 0; i < nDevices; i++) { dataSize = 0; GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, data, &dataSize); GetRawInputDeviceInfo(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, data, &dataSize); data[dataSize] = '\0'; if ((_tcsstr((TCHAR*)data, vidStr) > 0)) { memcpy(&rawInputDeviceList, &pRawInputDeviceList[i], sizeof(rawInputDeviceList)); break; } } memset(&rawInputDevice, 0, sizeof(rawInputDevice)); rawInputDevice.dwFlags = RIDEV_INPUTSINK; rawInputDevice.hwndTarget = hWnd; /* Set "Usage" and "Usage Page" for mouse * https://msdn.microsoft.com/en-us/library/windows/hardware/ff543477(v=vs.85).aspx */ rawInputDevice.usUsagePage = DEVICE_USAGE_PAGE; rawInputDevice.usUsage = DEVICE_USAGE; if (RegisterRawInputDevices(&rawInputDevice, 1, sizeof(rawInputDevice))) { result = TRUE; printf("Registered for raw inputs\n"); } else { printf("Registered for raw inputs failed. Error code 0x%08X.\n", GetLastError()); } } while (false); if (NULL != pRawInputDeviceList) { free(pRawInputDeviceList); } return result; }
ArrayBlock<RawMouse> getRawMouseArray() { UINT nDevices; PRAWINPUTDEVICELIST pRawInputDeviceList; list<RawMouse> rawMiceList; if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { showErrorMessageAndExit(L"GetRawInputDeviceList() count"); } pRawInputDeviceList = safeMallocExitOnFailure<RAWINPUTDEVICELIST>(nDevices); if (((INT) GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) < 0) { showErrorMessageAndExit(L"GetRawInputDeviceList() get"); } for (UINT currentDeviceIndex = 0; currentDeviceIndex < nDevices; currentDeviceIndex++) { DWORD currentDeviceType = pRawInputDeviceList[currentDeviceIndex].dwType; HANDLE hDevice = pRawInputDeviceList[currentDeviceIndex].hDevice; if (currentDeviceType == RIM_TYPEMOUSE) { UINT cbSize; TCHAR* psName; if (GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, NULL, &cbSize) != 0) { showErrorMessageAndExit(L"GetRawInputDeviceInfo() count"); } psName = safeMallocExitOnFailure<TCHAR>(cbSize); if (((INT) GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, psName, &cbSize)) < 0) { safe_free(&psName); showErrorMessageAndExit(L"GetRawInputDeviceInfo() get"); } assert(_tcsnlen(psName, cbSize) == cbSize - 1); // We want to ignore RDP mice { TCHAR rdpMouseName[] = _T("\\\\?\\Root#RDP_MOU#0000#"); size_t rdpMouseNameStrlen = _tcslen(rdpMouseName); if (_tcslen(psName) >= rdpMouseNameStrlen && _tcsncmp(rdpMouseName, psName, rdpMouseNameStrlen) == 0) { safe_free(&psName); continue; } } safe_free(&psName); if (GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO, NULL, &cbSize) != 0) { showErrorMessageAndExit(L"GetRawInputDeviceInfo() count"); } PRID_DEVICE_INFO pDeviceInfo = safeMallocBytesExitOnFailure<RID_DEVICE_INFO>(cbSize); pDeviceInfo->cbSize = cbSize; if (((INT) GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO, pDeviceInfo, &cbSize)) < 0) { showErrorMessageAndExit(L"GetRawInputDeviceInfo() get"); } assert(pDeviceInfo->dwType == RIM_TYPEMOUSE); RawMouse currentMouse; currentMouse.deviceHandle = pRawInputDeviceList[currentDeviceIndex].hDevice; currentMouse.x = 0; currentMouse.y = 0; currentMouse.z = 0; currentMouse.buttonsPressed = ArrayBlock<bool>(); currentMouse.buttonsPressed.allocate(pDeviceInfo->mouse.dwNumberOfButtons); memset(currentMouse.buttonsPressed.data(), 0, sizeof(bool)*currentMouse.buttonsPressed.count()); rawMiceList.push_back(currentMouse); } } safe_free(&pRawInputDeviceList); ArrayBlock<RawMouse> out_rawMiceArray; out_rawMiceArray.allocate(rawMiceList.size()); size_t currentPos = 0; for (list<RawMouse>::iterator rawMouseIt = rawMiceList.begin(); rawMouseIt != rawMiceList.end(); rawMouseIt++) { out_rawMiceArray.data()[currentPos] = *rawMouseIt; currentPos++; } return out_rawMiceArray; }
static bool winraw_init_devices(winraw_mouse_t **mice, unsigned *mouse_cnt) { UINT i; POINT crs_pos; winraw_mouse_t *mice_r = NULL; unsigned mouse_cnt_r = 0; RAWINPUTDEVICELIST *devs = NULL; UINT dev_cnt = 0; UINT r = GetRawInputDeviceList( NULL, &dev_cnt, sizeof(RAWINPUTDEVICELIST)); if (r == (UINT)-1) { RARCH_ERR("[WINRAW]: GetRawInputDeviceList failed with error %lu.\n", GetLastError()); goto error; } devs = (RAWINPUTDEVICELIST*)malloc(dev_cnt * sizeof(RAWINPUTDEVICELIST)); if (!devs) goto error; dev_cnt = GetRawInputDeviceList(devs, &dev_cnt, sizeof(RAWINPUTDEVICELIST)); if (dev_cnt == (UINT)-1) { RARCH_ERR("[WINRAW]: GetRawInputDeviceList failed with error %lu.\n", GetLastError()); goto error; } for (i = 0; i < dev_cnt; ++i) mouse_cnt_r += devs[i].dwType == RIM_TYPEMOUSE ? 1 : 0; if (mouse_cnt_r) { mice_r = (winraw_mouse_t*)calloc(1, mouse_cnt_r * sizeof(winraw_mouse_t)); if (!mice_r) goto error; if (!GetCursorPos(&crs_pos)) goto error; for (i = 0; i < mouse_cnt_r; ++i) { mice_r[i].x = crs_pos.x; mice_r[i].y = crs_pos.y; } } /* count is already checked, so this is safe */ for (i = mouse_cnt_r = 0; i < dev_cnt; ++i) { if (devs[i].dwType == RIM_TYPEMOUSE) mice_r[mouse_cnt_r++].hnd = devs[i].hDevice; } winraw_log_mice_info(mice_r, mouse_cnt_r); *mice = mice_r; *mouse_cnt = mouse_cnt_r; return true; error: free(devs); free(mice_r); *mice = NULL; *mouse_cnt = 0; return false; }
BOOL ConnectNIA(HWND hDlg) { UINT ui; UINT ret; ret=GetRawInputDeviceList(NULL,&ui,0); UINT i; int sav_pause; write_logfile("Connecting NIA"); sav_pause=TTY.read_pause; TTY.read_pause=1; ret=GetRegisteredRawInputDevices(NULL,&ui,sizeof(RAWINPUTDEVICE)); // get size if (ret<=sizeof(Rid)) // if okay, get structures GetRegisteredRawInputDevices(Rid, &ui, sizeof(RAWINPUTDEVICE)); if (ui>0) { write_logfile("NIA already connected!"); TTY.read_pause=sav_pause; return (TRUE); } m_hNIA[0]=NULL; m_hNIA[1]=NULL; ui=20; ret=GetRawInputDeviceList(&RawInputDeviceList[0],&ui,sizeof(RAWINPUTDEVICELIST)); if(ret!=(UINT)-1) { RID_DEVICE_INFO dev_info ; TCHAR strName[300]; m_nCountNIA = 0; for(i=0;i<ret;i++) { if(i>=20) break; dev_info.cbSize=sizeof(RID_DEVICE_INFO); ui=sizeof(RID_DEVICE_INFO); GetRawInputDeviceInfo(RawInputDeviceList[i].hDevice,RIDI_DEVICEINFO,&dev_info,&ui); ui=300; GetRawInputDeviceInfo(RawInputDeviceList[i].hDevice,RIDI_DEVICENAME,strName,&ui); if(dev_info.hid.dwVendorId==0x1234 /*&& dev_info.hid.dwProductId==0*/) { if(m_nCountNIA>=2) break; // nur an dieser Stelle vorbereitet! m_hNIA[m_nCountNIA]=RawInputDeviceList[i].hDevice; Rid[m_nCountNIA].usUsagePage = 0xFF00; Rid[m_nCountNIA].usUsage = 0xFF01; Rid[m_nCountNIA].dwFlags = RIDEV_INPUTSINK; // this enables the caller to receive the input even when the caller is not in the foreground. Note that hwndTarget must be specified. Rid[m_nCountNIA].hwndTarget = ghWndMain ; // directs Data to main Thread !! m_nCountNIA++; // ToDo: für 2 NIA Devices 2! Channels in Amplifier??? (not tested yet!) } } } else { TTY.read_pause=sav_pause; return (FALSE) ; } if(m_nCountNIA>0) { if (RegisterRawInputDevices(Rid, m_nCountNIA, sizeof(RAWINPUTDEVICE)) == FALSE) { write_logfile("Could not register NIA"); report_error("Could not register NIA"); TTY.read_pause=sav_pause; return FALSE; } else { if (hDlg!=NULL) { SetDlgItemText( hDlg, IDC_PORTCOMBO, "none") ; TTY.read_pause=sav_pause; return TRUE; } } } TTY.read_pause=sav_pause; return FALSE; }
//////////////////////////////////////////////////////////////////////////// //! Find wiimote device //////////////////////////////////////////////////////////////////////////// int wiimoteInput::findWiimote(void) { UINT nDevices; PRAWINPUTDEVICELIST pRawInputDeviceList; if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { ILOG("GetRawInputDeviceList failed."); return (-1); } if ((pRawInputDeviceList = new RAWINPUTDEVICELIST[nDevices]) == NULL) { ILOG("Allocate memory failed."); return (-1); } if (GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)) == -1) { ILOG("GetRawInputDeviceList(2) failed."); return (-1); } WCHAR pathName[WIIMOTE_STICK_PATHNAME_MAX]; PRAWINPUTDEVICELIST pDev; RID_DEVICE_INFO info; UINT bufSize; wiiStick* pws = NULL; for (unsigned int i = 0; i < nDevices; i ++) { pDev = &pRawInputDeviceList[i]; bufSize = sizeof(info); info.cbSize = sizeof(info); if (GetRawInputDeviceInfo(pDev->hDevice, RIDI_DEVICEINFO, &info, &bufSize) > 0) { // is general hid device ? if (RIM_TYPEHID == info.dwType) { // is wiimote ? if ( (WIIMOTE_VENDOR_ID == info.hid.dwVendorId) && (WIIMOTE_PRODUCT_ID == info.hid.dwProductId) && (WIIMOTE_USAGE_PAGE == info.hid.usUsagePage) && (WIIMOTE_USAGE == info.hid.usUsage) ) { bufSize = WIIMOTE_STICK_PATHNAME_MAX; if (GetRawInputDeviceInfo( pDev->hDevice, RIDI_DEVICENAME, pathName, &bufSize) > 0) { /////////////////////////////////////////////////// // HOTFIX !!! // The 2nd char of device name is mistaked by '?' // in returns of GetRawInputDeviceInfo() /////////////////////////////////////////////////// pathName[1] = '\\'; /////////////////////////////////////////////////// wchar_t *wiimote_id = L"\\\\?\\HID#BTHIDJOYSTK#2"; if (wcsncmp(pathName, wiimote_id, wcslen(wiimote_id)) != 0) { // NOT WIIMOTE ILOG("Not wiimote."); } else { INEW_SOLO(pws, wiiStick); if ((count < WIIMOTE_STICK_NUMBER_MAX) && pws->init(pathName)) { stick[count] = pws; // wiiStick object rawHandle[count] = pDev->hDevice; // raw handle count ++; } else { IDELETE_SOLO(pws); } } } else { ILOG("GetRawInputDeviceInfo failed."); delete []pRawInputDeviceList; return (-1); } } // wiimote } // hid } } // after the job, free the RAWINPUTDEVICELIST delete []pRawInputDeviceList; return (count); }
void WIN_InitMouse(_THIS) { int index = 0; RAWINPUTDEVICELIST *deviceList = NULL; int devCount = 0; int i; int tmp = 0; char *buffer = NULL; char *tab = "wacom"; /* since windows does't give us handles to tablets, we have to detect a tablet by it's name */ const char *rdp = "rdp_mou"; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; /* WinCE has no RawInputDeviceList */ #ifdef _WIN32_WCE SDL_Mouse mouse; SDL_zero(mouse); mouse.id = 0; SDL_AddMouse(&mouse, "Stylus", 0, 0, 1); #else /* we're checking for the number of rawinput devices */ if (GetRawInputDeviceList(NULL, &devCount, sizeof(RAWINPUTDEVICELIST))) { return; } deviceList = SDL_malloc(sizeof(RAWINPUTDEVICELIST) * devCount); /* we're getting the raw input device list */ GetRawInputDeviceList(deviceList, &devCount, sizeof(RAWINPUTDEVICELIST)); mice = SDL_malloc(devCount * sizeof(HANDLE)); /* we're getting the details of the devices */ for (i = 0; i < devCount; ++i) { int is_rdp = 0; int j; int k; char *default_device_name = "Pointing device xx"; const char *reg_key_root = "System\\CurrentControlSet\\Enum\\"; char *device_name = SDL_malloc(256 * sizeof(char)); char *key_name = NULL; char *tmp_name = NULL; LONG rc = 0; HKEY hkey; DWORD regtype = REG_SZ; DWORD out = 256 * sizeof(char); SDL_Mouse mouse; int l; if (deviceList[i].dwType != RIM_TYPEMOUSE) { /* if a device isn't a mouse type we don't want it */ continue; } if (GetRawInputDeviceInfoA (deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp) < 0) { continue; } buffer = SDL_malloc((tmp + 1) * sizeof(char)); key_name = SDL_malloc((tmp + SDL_strlen(reg_key_root) + 1) * sizeof(char)); /* we're getting the device registry path and polishing it to get it's name, surely there must be an easier way, but we haven't found it yet */ if (GetRawInputDeviceInfoA (deviceList[i].hDevice, RIDI_DEVICENAME, buffer, &tmp) < 0) { continue; } buffer += 4; tmp -= 4; tmp_name = buffer; for (j = 0; j < tmp; ++j) { if (*tmp_name == '#') { *tmp_name = '\\'; } else if (*tmp_name == '{') { break; } ++tmp_name; } *tmp_name = '\0'; SDL_memcpy(key_name, reg_key_root, SDL_strlen(reg_key_root)); SDL_memcpy(key_name + (SDL_strlen(reg_key_root)), buffer, j + 1); l = SDL_strlen(key_name); is_rdp = 0; if (l >= 7) { for (j = 0; j < l - 7; ++j) { for (k = 0; k < 7; ++k) { if (rdp[k] != SDL_tolower((unsigned char) key_name[j + k])) { break; } } if (k == 7) { is_rdp = 1; break; } } } buffer -= 4; if (is_rdp == 1) { SDL_free(buffer); SDL_free(key_name); SDL_free(device_name); is_rdp = 0; continue; } /* we're opening the registry key to get the mouse name */ rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey); if (rc != ERROR_SUCCESS) { SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); } rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, ®type, device_name, &out); RegCloseKey(hkey); if (rc != ERROR_SUCCESS) { SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); } /* we're saving the handle to the device */ mice[index] = deviceList[i].hDevice; SDL_zero(mouse); mouse.id = index; l = SDL_strlen(device_name); /* we're checking if the device isn't by any chance a tablet */ if (data->wintabDLL && tablet == -1) { for (j = 0; j < l - 5; ++j) { for (k = 0; k < 5; ++k) { if (tab[k] != SDL_tolower((unsigned char) device_name[j + k])) { break; } } if (k == 5) { tablet = index; break; } } } /* if it's a tablet, let's read it's maximum and minimum pressure */ if (tablet == index) { AXIS pressure; int cursors; data->WTInfoA(WTI_DEVICES, DVC_NPRESSURE, &pressure); data->WTInfoA(WTI_DEVICES, DVC_NCSRTYPES, &cursors); SDL_AddMouse(&mouse, device_name, pressure.axMax, pressure.axMin, cursors); } else { SDL_AddMouse(&mouse, device_name, 0, 0, 1); } ++index; SDL_free(buffer); SDL_free(key_name); } total_mice = index; SDL_free(deviceList); #endif /*_WIN32_WCE*/ }
bool EventHandler::initMagellan(Node* node) { #ifdef EQUALIZER_USE_MAGELLAN _magellanGotRotation = false; _magellanGotTranslation = false; // Find the Raw Devices UINT nDevices; // Get Number of devices attached if (GetRawInputDeviceList(0, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { LBINFO << "No RawInput devices attached" << std::endl; return false; } // Create list large enough to hold all RAWINPUTDEVICE structs _pRawInputDeviceList = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); if (!_pRawInputDeviceList) { LBINFO << "Error mallocing RAWINPUTDEVICELIST" << std::endl; return false; } // Now get the data on the attached devices if (GetRawInputDeviceList(_pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)) == -1) { LBINFO << "Error from GetRawInputDeviceList" << std::endl; return false; } _rawInputDevices = (PRAWINPUTDEVICE)alloca(nDevices * sizeof(RAWINPUTDEVICE)); _nRawInputDevices = 0; // Look through device list for RIM_TYPEHID devices with UsagePage == 1, // Usage == 8 for (UINT i = 0; i < nDevices; ++i) { if (_pRawInputDeviceList[i].dwType == RIM_TYPEHID) { UINT nchars = 300; TCHAR deviceName[300]; if (GetRawInputDeviceInfo(_pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, deviceName, &nchars) >= 0) { LBINFO << "Device [" << i << "]: handle=" << _pRawInputDeviceList[i].hDevice << " name = " << deviceName << std::endl; } RID_DEVICE_INFO dinfo; UINT sizeofdinfo = sizeof(dinfo); dinfo.cbSize = sizeofdinfo; if (GetRawInputDeviceInfo(_pRawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &dinfo, &sizeofdinfo) >= 0) { if (dinfo.dwType == RIM_TYPEHID) { RID_DEVICE_INFO_HID* phidInfo = &dinfo.hid; LBINFO << "VID = " << phidInfo->dwVendorId << std::endl << "PID = " << phidInfo->dwProductId << std::endl << "Version = " << phidInfo->dwVersionNumber << std::endl << "UsagePage = " << phidInfo->usUsagePage << std::endl << "Usage = " << phidInfo->usUsage << std::endl; // Add this one to the list of interesting devices? // Actually only have to do this once to get input from all // usage 1, usagePage 8 devices This just keeps out the // other usages. You might want to put up a list for users // to select amongst the different devices. In particular, // to assign separate functionality to the different // devices. if (phidInfo->usUsagePage == 1 && phidInfo->usUsage == 8) { _rawInputDevices[_nRawInputDevices].usUsagePage = phidInfo->usUsagePage; _rawInputDevices[_nRawInputDevices].usUsage = phidInfo->usUsage; _rawInputDevices[_nRawInputDevices].dwFlags = 0; _rawInputDevices[_nRawInputDevices].hwndTarget = 0; ++_nRawInputDevices; } } } } } // Register for input from the devices in the list if (RegisterRawInputDevices(_rawInputDevices, _nRawInputDevices, sizeof(RAWINPUTDEVICE)) == FALSE) { LBVERB << "Error calling RegisterRawInputDevices" << std::endl; return false; } LBINFO << "Found and connected." << std::endl; _magellanNode = node; #endif return true; }
bool SoWinP::InitRawDevices(void) { PRAWINPUTDEVICELIST rawInputDeviceList; PRAWINPUTDEVICE rawInputDevices; int usagePage1Usage8Devices; // Find the Raw Devices UINT nDevices; // Get Number of devices attached if (GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { return FALSE; } // Create list large enough to hold all RAWINPUTDEVICE structs rawInputDeviceList = (PRAWINPUTDEVICELIST) malloc(sizeof(RAWINPUTDEVICELIST) * nDevices); if (rawInputDeviceList == NULL) { return FALSE; } // Now get the data on the attached devices if (GetRawInputDeviceList(rawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST)) == -1) { return FALSE; } rawInputDevices = (PRAWINPUTDEVICE) malloc(nDevices * sizeof(RAWINPUTDEVICE)); usagePage1Usage8Devices = 0; // Look through device list for RIM_TYPEHID devices with UsagePage == 1, Usage == 8 for(UINT i=0; i<nDevices; i++) { if (rawInputDeviceList[i].dwType == RIM_TYPEHID) { UINT nchars = 300; TCHAR deviceName[300]; RID_DEVICE_INFO dinfo; UINT sizeofdinfo = sizeof(dinfo); dinfo.cbSize = sizeofdinfo; if (GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &dinfo, &sizeofdinfo ) >= 0) { if (dinfo.dwType == RIM_TYPEHID) { RID_DEVICE_INFO_HID *phidInfo = &dinfo.hid; // Add this one to the list of interesting devices? // Actually only have to do this once to get input from all // usage 1, usagePage 8 devices This just keeps out the // other usages. You might want to put up a list for users // to select amongst the different devices. In particular, // to assign separate functionality to the different // devices. if (phidInfo->usUsagePage == 1 && phidInfo->usUsage == 8) { rawInputDevices[usagePage1Usage8Devices].usUsagePage = phidInfo->usUsagePage; rawInputDevices[usagePage1Usage8Devices].usUsage = phidInfo->usUsage; rawInputDevices[usagePage1Usage8Devices].dwFlags = 0; rawInputDevices[usagePage1Usage8Devices].hwndTarget = mainWidget;//NULL; usagePage1Usage8Devices++; } } } } } // Register for input from the devices in the list if (RegisterRawInputDevices(rawInputDevices, usagePage1Usage8Devices, sizeof(RAWINPUTDEVICE)) == FALSE) { return FALSE; } return TRUE; }