Вверх ↑
Ответов: 3349
Рейтинг: 233
#1: 2011-06-19 09:58:55 ЛС | профиль | цитата
Первый эксперимент с RawInput.Перечисляет устройства
Add(MainForm,5093709,161,154)
{
Width=600
Height=437
link(onCreate,4674337:doEnum,[])
}
Add(InlineCode,4674337,210,168)
{
WorkPoints=#6:doEnum|
EventPoints=#8:onDevice|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|29:uses kol,Share,Debug,Windows;|0:|4:type|31: tagRAWINPUTDEVICELIST = record|18: hDevice:THandle;|15: dwType:DWORD;|5: end;|0:|32: tagRID_DEVICE_INFO_HID = record|22: dwVendorId: DWORD;|23: dwProductId: DWORD;|27: dwVersionNumber: DWORD;|22: usUsagePage: WORD;|18: usUsage: WORD;|6: end;|0:|37: tagRID_DEVICE_INFO_KEYBOARD = record|18: dwType: DWORD;|21: dwSubType: DWORD;|26: dwKeyboardMode: DWORD;|34: dwNumberOfFunctionKeys: DWORD;|32: dwNumberOfIndicators: DWORD;|31: dwNumberOfKeysTotal: DWORD;|7: end; |1: |34: tagRID_DEVICE_INFO_MOUSE = record|16: dwId: DWORD;|29: dwNumberOfButtons: DWORD;|24: dwSampleRate: DWORD;|7: end; |2: |52: RID_DEVICE_INFO_HID = tagRID_DEVICE_INFO_HID;|58: RID_DEVICE_INFO_KEYBOARD = tagRID_DEVICE_INFO_KEYBOARD; |54: RID_DEVICE_INFO_MOUSE = tagRID_DEVICE_INFO_MOUSE;|0:|28: tagRID_DEVICE_INFO = record|18: cbSize: DWORD;|18: dwType: DWORD;|19: case Integer of|38: 0: (mouse: RID_DEVICE_INFO_MOUSE);|44: 1: (keyboard: RID_DEVICE_INFO_KEYBOARD);|34: 2: (hid: RID_DEVICE_INFO_HID);|6: end;|38: RID_DEVICE_INFO = tagRID_DEVICE_INFO;|1: |45: TRAWINPUTDEVICELIST = tagRAWINPUTDEVICELIST;|44: PRAWINPUTDEVICELIST = ^TRAWINPUTDEVICELIST;|0:|78: TGetRawInputDeviceList = function (pRawInputDeviceList: PRAWINPUTDEVICELIST;|58: var puiNumDevices: UINT; cbSize: UINT): UINT; stdcall;|4: |87: TGetRawInputDeviceInfo = function (hDevice: THANDLE; uiCommand: UINT; pData: POINTER;|38: var pcbSize: UINT): UINT; stdcall;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|28: User32DllHandle:THandle;|49: GetRawInputDeviceList:TGetRawInputDeviceList;|52: RAWINPUTDEVICELIST:array of TRAWINPUTDEVICELIST;|49: GetRawInputDeviceInfo:TGetRawInputDeviceInfo;|9: public|23: onDevice:THI_Event;|3: |45: procedure doEnum(var dt:TData; idx:word);|5: end;|0:|14:implementation|0:|40:const USER32 = 'User32.DLL';|29: RIM_TYPEHID = 2;|29: RIM_TYPEKEYBOARD = 1;|29: RIM_TYPEMOUSE = 0;|37: RIDI_DEVICENAME = $20000007;|37: RIDI_DEVICEINFO = $2000000b;|37: RIDI_PREPARSEDDATA = $20000005;|0:|31:function IsWindowsNt():boolean;|33:var OSVersionInfo:TOSVersionInfo;|5:begin|15: Result:=false;|50: FillChar(OSVersionInfo,SizeOf(TOSVersionInfo),0);|61: OSVersionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);|29: GetVersionEx(OSVersionInfo);|69: result := OSVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT; |14: result:=true;|4:end;|0:|29:procedure THiAsmClass.doEnum;|13:var c,s:UINT;|14: i:integer;|33: n:array[0..1023] of AnsiChar;|17: t,name:TData;|5:begin|20: if IsWindowsNt then|7: begin|47: User32DllHandle := GetModuleHandle(USER32);|31: if User32DllHandle = 0 then|9: begin|45: User32DllHandle := LoadLibrary(USER32);|14: end; |87: @GetRawInputDeviceList := GetProcAddress(User32DllHandle, 'GetRawInputDeviceList');|88: @GetRawInputDeviceInfo := GetProcAddress(User32DllHandle, 'GetRawInputDeviceInfoA');|11: c := 0;|61: GetRawInputDeviceList(nil,c,SizeOf(TRAWINPUTDEVICELIST));|92: SetLength(RAWINPUTDEVICELIST,c); |80: GetRawInputDeviceList(@RAWINPUTDEVICELIST[0],c,SizeOf(TRAWINPUTDEVICELIST));|30: for i:=0 to c - 1 do begin|79: GetRawInputDeviceInfo(RAWINPUTDEVICELIST[i].hDevice,RIDI_DEVICENAME,@n,s);|41: case RAWINPUTDEVICELIST[i].dwType of|42: RIM_TYPEHID: dtString(t,'HID');|44: RIM_TYPEMOUSE: dtString(t,'MOUSE');|53: RIM_TYPEKEYBOARD: dtString(t,'KEYBOARD'); |9: end;|22: dtString(name,n);|22: t.ldata := @name;|29: _hi_OnEvent(onDevice,t);|8: end;|6: end;|4:end;|0:|4:end.|
link(onDevice,4274780:doStr,[])
}
Add(StringTable,12067686,322,168)
{
Top=25
Width=600
Height=375
Columns=#8:type=100|8:name=495|
}
Add(MT_String,4274780,266,168)
{
link(onResult,12067686:doAdd,[])
}


карма: 1

1
файлы: 1code_24419.txt [4KB] [546]
Голосовали:1nd1g0