+++ /dev/null
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-\r
-#include <windows.h>\r
-\r
-#include "../stack_array.h"\r
-#include "../Utilities.h"\r
-#include "../SlimDXException.h"\r
-\r
-#include "DeviceRI.h"\r
-#include "KeyboardInfo.h"\r
-#include "MouseInfo.h"\r
-#include "HidInfo.h"\r
-\r
-using namespace System;\r
-using namespace System::ComponentModel;\r
-using namespace System::Windows::Forms;\r
-using namespace System::Collections::ObjectModel;\r
-using namespace System::Collections::Generic;\r
-\r
-namespace SlimDX\r
-{\r
-namespace RawInput\r
-{\r
- void Device::RegisterDevice( SlimDX::Multimedia::UsagePage usagePage, SlimDX::Multimedia::UsageId usageId, DeviceFlags flags )\r
- {\r
- RegisterDevice( usagePage, usageId, flags, IntPtr::Zero );\r
- }\r
-\r
- void Device::RegisterDevice( SlimDX::Multimedia::UsagePage usagePage, SlimDX::Multimedia::UsageId usageId, DeviceFlags flags, IntPtr target )\r
- {\r
- RAWINPUTDEVICE device;\r
- device.usUsagePage = static_cast<USHORT>( usagePage );\r
- device.usUsage = static_cast<USHORT>( usageId );\r
- device.dwFlags = static_cast<DWORD>( flags );\r
- device.hwndTarget = static_cast<HWND>( target.ToPointer() );\r
-\r
- if( RegisterRawInputDevices( &device, 1, sizeof(RAWINPUTDEVICE) ) <= 0 )\r
- throw gcnew Win32Exception();\r
-\r
- if( filter == nullptr )\r
- {\r
- filter = gcnew InputMessageFilter();\r
- Application::AddMessageFilter( filter );\r
- }\r
- }\r
-\r
- void Device::OnWmInput( HRAWINPUT handle )\r
- {\r
- UINT size = 0;\r
- GetRawInputData( handle, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER) );\r
-\r
- if( size == 0 )\r
- return;\r
-\r
- // Manual Allocation: cleaned up in the try/finally clause below\r
- BYTE *bytes = new BYTE[size];\r
-\r
- try\r
- {\r
- GetRawInputData( handle, RID_INPUT, bytes, &size, sizeof(RAWINPUTHEADER) );\r
-\r
- RAWINPUT *rawInput = reinterpret_cast<RAWINPUT*>( bytes );\r
-\r
- if( rawInput->header.dwType == RIM_TYPEKEYBOARD )\r
- {\r
- KeyboardInput( nullptr, gcnew KeyboardInputEventArgs( rawInput->data.keyboard.MakeCode,\r
- static_cast<ScanCodeFlags>( rawInput->data.keyboard.Flags ),\r
- static_cast<Keys>( rawInput->data.keyboard.VKey ),\r
- static_cast<KeyState>( rawInput->data.keyboard.Message ),\r
- rawInput->data.keyboard.ExtraInformation, IntPtr( rawInput->header.hDevice ) ) );\r
- }\r
- else if( rawInput->header.dwType == RIM_TYPEMOUSE )\r
- {\r
- MouseInput( nullptr, gcnew MouseInputEventArgs( static_cast<MouseMode>( rawInput->data.mouse.usFlags ),\r
- static_cast<MouseButtonFlags>( rawInput->data.mouse.usButtonFlags ),\r
- static_cast<short>( rawInput->data.mouse.usButtonData ),\r
- rawInput->data.mouse.ulRawButtons,\r
- rawInput->data.mouse.lLastX,\r
- rawInput->data.mouse.lLastY,\r
- rawInput->data.mouse.ulExtraInformation, IntPtr( rawInput->header.hDevice ) ) );\r
- }\r
- else\r
- {\r
- int length = rawInput->data.hid.dwCount * rawInput->data.hid.dwSizeHid;\r
- array<Byte>^ bytes = gcnew array<Byte>( length );\r
- for( int i = 0; i < length; i++ )\r
- bytes[i] = rawInput->data.hid.bRawData[i];\r
-\r
- RawInput( nullptr, gcnew RawInputEventArgs( rawInput->data.hid.dwSizeHid, rawInput->data.hid.dwCount, bytes, IntPtr( rawInput->header.hDevice ) ) );\r
- }\r
- }\r
- finally\r
- {\r
- delete[] bytes;\r
- }\r
- }\r
-\r
- ReadOnlyCollection<DeviceInfo^>^ Device::GetDevices()\r
- {\r
- List<DeviceInfo^>^ devices = gcnew List<DeviceInfo^>();\r
- UINT count = 0;\r
-\r
- if( GetRawInputDeviceList( NULL, &count, sizeof(RAWINPUTDEVICELIST) ) != 0 )\r
- throw gcnew Win32Exception();\r
-\r
- if( count == 0 )\r
- return nullptr;\r
-\r
- stack_array<RAWINPUTDEVICELIST> deviceList = stackalloc( RAWINPUTDEVICELIST, count );\r
- if( GetRawInputDeviceList( &deviceList[0], &count, sizeof(RAWINPUTDEVICELIST) ) == -1 )\r
- throw gcnew Win32Exception();\r
-\r
- for( unsigned int i = 0; i < count; i++ )\r
- {\r
- UINT size = 0;\r
- BYTE *bytes;\r
- String^ name;\r
-\r
- GetRawInputDeviceInfo( deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &size );\r
-\r
- if( size != 0 )\r
- {\r
- stack_array<TCHAR> chars = stackalloc( TCHAR, size );\r
- GetRawInputDeviceInfo( deviceList[i].hDevice, RIDI_DEVICENAME, &chars[0], &size );\r
-\r
- name = gcnew String( &chars[0] );\r
- }\r
-\r
- GetRawInputDeviceInfo( deviceList[i].hDevice, RIDI_DEVICEINFO, NULL, &size );\r
-\r
- if( size == 0 )\r
- continue;\r
-\r
- // Manual Allocation: cleaned up by the try/finally clause below\r
- bytes = new BYTE[size];\r
-\r
- try\r
- {\r
- RID_DEVICE_INFO *nativeInfo = reinterpret_cast<RID_DEVICE_INFO*>( bytes );\r
- nativeInfo->cbSize = sizeof( RID_DEVICE_INFO );\r
-\r
- GetRawInputDeviceInfo( deviceList[i].hDevice, RIDI_DEVICEINFO, nativeInfo, &size ); \r
-\r
- if( nativeInfo->dwType == RIM_TYPEKEYBOARD )\r
- {\r
- KeyboardInfo^ info = gcnew KeyboardInfo();\r
-\r
- info->DeviceType = static_cast<DeviceType>( nativeInfo->dwType );\r
- info->DeviceName = name;\r
- info->Handle = IntPtr( deviceList[i].hDevice );\r
- info->KeyboardType = nativeInfo->keyboard.dwType;\r
- info->Subtype = nativeInfo->keyboard.dwSubType;\r
- info->KeyboardMode = nativeInfo->keyboard.dwKeyboardMode;\r
- info->FunctionKeyCount = nativeInfo->keyboard.dwNumberOfFunctionKeys;\r
- info->IndicatorCount = nativeInfo->keyboard.dwNumberOfIndicators;\r
- info->TotalKeyCount = nativeInfo->keyboard.dwNumberOfKeysTotal;\r
-\r
- devices->Add( info );\r
- }\r
- else if( nativeInfo->dwType == RIM_TYPEMOUSE )\r
- {\r
- MouseInfo^ info = gcnew MouseInfo();\r
-\r
- info->DeviceType = static_cast<DeviceType>( nativeInfo->dwType );\r
- info->DeviceName = name;\r
- info->Handle = IntPtr( deviceList[i].hDevice );\r
- info->Id = nativeInfo->mouse.dwId;\r
- info->ButtonCount = nativeInfo->mouse.dwNumberOfButtons;\r
- info->SampleRate = nativeInfo->mouse.dwSampleRate;\r
-\r
- devices->Add( info );\r
- }\r
- else\r
- {\r
- HidInfo^ info = gcnew HidInfo();\r
-\r
- info->DeviceType = static_cast<DeviceType>( nativeInfo->dwType );\r
- info->DeviceName = name;\r
- info->Handle = IntPtr( deviceList[i].hDevice );\r
- info->VendorId = nativeInfo->hid.dwVendorId;\r
- info->ProductId = nativeInfo->hid.dwProductId;\r
- info->VersionNumber = nativeInfo->hid.dwVersionNumber;\r
-\r
- devices->Add( info );\r
- }\r
- }\r
- finally\r
- {\r
- delete[] bytes;\r
- }\r
- }\r
-\r
- return gcnew ReadOnlyCollection<DeviceInfo^>( devices );\r
- }\r
-}\r
-}
\ No newline at end of file