Вверх ↑
Ответов: 3889
Рейтинг: 362
#1: 2011-06-20 23:18:48 ЛС | профиль | цитата
Windows 7 32 bit Tablet PC - RAW INPUT
------------ Дoбавленo в 23.18:
Ivann, творческих озарений во сне, я последую твоему примеру. Как видишь, на Win7 32 bit все твои примеры работают, на скриншоте планшет Toshiba и его тачпад, перо, клавиатура и куча спецустройств HID, включая акселлерометр (датчик положения). Так что ненулевая вероятность, что проблемы в 64-битной системе с её эмуляцией. Впечатление, будто там 64-хбитный RawInput, оттуда такие гигантские числа в сканкодах

Если у кого-то из сочувствующих под рукой 64-хразрядная система, проверьте, пожалуйста, работу пары схем:

Опрос устройств интерфейса с человеком в системе:

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,[])
}


Глобальный захват нажатий мыши и клавиатуры без hook.dll, рекомендуемый Microsoft (по MSDN). Требуется модуль RInput.pas от из этого архива, достаточно переташить папку HiAsm на одноимённую папку с установленной средой у Вас.




Add(MainForm,3921136,315,189)
{
Point(PHandle)
link(onCreate,8770334:SetRawInput,[(359,209)(359,244)(303,244)(303,279)])
}
Add(InlineCode,8770334,315,273)
{
WorkPoints=#11:SetRawInput|
EventPoints=#9:onKeyDown|7:onKeyUp|8:onRepeat|12:onMouseEvent|0:|
VarPoints=#1:X|1:Y|5:Flags|6:BFlags|
DataPoints=#7:Control|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|45:uses kol,Share,Debug,Windows,RInput,Messages;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|26: OldMessage:TOnMessage;|18: ctrl:PControl;|17: key,mes:UINT;|33: mx,my,_flags,_bflags:integer;|4: |68: function onMessage( var Msg: TMsg; var Rslt: Integer ): Boolean;|10: public |4: |62: Control,onKeyDown,onKeyUp,onRepeat,onMouseEvent:THI_Event;|3: |50: procedure SetRawInput(var dt:TData; Idx:WORD);|40: procedure X(var dt:TData; Idx:WORD);|40: procedure Y(var dt:TData; Idx:WORD);|44: procedure Flags(var dt:TData; Idx:WORD);|45: procedure BFlags(var dt:TData; Idx:WORD);|5: end;|0:|14:implementation|0:|34:procedure THiAsmClass.SetRawInput;|38:var rid:array[0..1] of RAWINPUTDEVICE;|5:begin|43: ctrl:=PControl(ReadInteger(dt,Control));|32: OldMessage := ctrl.OnMessage;|35: Ctrl.OnMessage := onMessage; |27: RID[0].usUsagePage := 1;|27: RID[0].usUsage := 6;|40: RID[0].dwFlags := RIDEV_NOLEGACY;|38: RID[0].hwndTarget := Ctrl.Handle; |27: RID[1].usUsagePage := 1;|27: RID[1].usUsage := 2;|41: RID[1].dwFlags := RIDEV_INPUTSINK;|40: RID[1].hwndTarget := Ctrl.Handle; |58: RegisterRawInputDevices(@RID,2,SizeOf(RAWINPUTDEVICE));|5:end; |0:|76:function THiAsmClass.onMessage( var Msg: TMsg; var Rslt: Integer ): Boolean;|6:const |22: WM_INPUT = $00FF;|17:var RI:RAWINPUT;|12: s:UINT;|15: t,f:TData;|5:begin|30:if Msg.message = WM_INPUT then|14: begin |22: s:=SizeOf(RAWINPUT);|81: GetRawInputData(HRAWINPUT(Msg.lParam),RID_HEADER,@RI,s,SizeOf(RAWINPUTHEADER));|27: case Ri.Header.dwType of |20: RIM_TYPEKEYBOARD:|9: begin|83: GetRawInputData(HRAWINPUT(Msg.lParam),RID_INPUT,@RI,s,SizeOf(RAWINPUTHEADER));|114: if (key = RI.keyboard.vKey) and (mes = RI.keyboard.message) then _hi_OnEvent(onRepeat, RI.keyboard.vKey) else|33: case RI.keyboard.message of|58: WM_KEYDOWN:_hi_OnEvent(onKeyDown,RI.keyboard.vKey);|55: WM_KEYUP: _hi_OnEvent(onKeyUp,RI.keyboard.vKey);|10: end;|8: end;|18: RIM_TYPEMOUSE: |9: begin|83: GetRawInputData(HRAWINPUT(Msg.lParam),RID_INPUT,@RI,s,SizeOf(RAWINPUTHEADER));|32: _flags := ri.Mouse.usFlags;|45: _bflags := ri.Mouse.union.usButtonFlags;|30: mx := ri.mouse.lLastX; |29: mY := ri.mouse.lLastY; |30: _hi_OnEvent(onMouseEvent);|8: end;|7: end; |27: key := RI.keyboard.vKey;|30: mes := RI.keyboard.message;|4:end;|45:Result := _hi_OnMessage(OldMessage,Msg,Rslt);|4:end;|0:|24:procedure THiAsmClass.X;|5:begin|18: dtInteger(dt,mx);|5:end; |0:|24:procedure THiAsmClass.Y;|5:begin|18: dtInteger(dt,my);|5:end; |0:|28:procedure THiAsmClass.Flags;|5:begin|22: dtInteger(dt,_flags);|5:end; |0:|29:procedure THiAsmClass.BFlags;|5:begin|23: dtInteger(dt,_bflags);|5:end; |0:|4:end.|
link(onKeyDown,7930936:doWork1,[])
link(onKeyUp,7930936:doWork2,[])
link(onRepeat,7930936:doWork3,[])
link(onMouseEvent,393041:doBits,[(359,300)(359,352)(324,352)(324,405)])
link(Control,3921136:PHandle,[])
}
Add(ChanelToIndex,7930936,427,273)
{
Count=3
Point(Data)
link(onIndex,7108844:doGetString,[(467,279)(467,314)])
}
Add(StrList,7108844,476,266)
{
Strings=#14:Нажата клавиша|15:Опущена клавиша|20:Удерживается клавиша|
Point(doGetString)
Point(onGetString)
link(onGetString,3750159:doString,[])
}
Add(FormatStr,3750159,525,273)
{
link(onFString,7567543:doWork2,[])
link(Str2,7930936:Data,[(538,261)(568,261)(568,330)(433,330)])
}
Add(ListBox,15090687,595,273)
{
Left=50
Top=60
Width=130
Height=200
Align=5
AddType=1
}
Add(IntToBits,393041,336,399)
{
ZeroBits=1
link(Value,8770334:BFlags,[])
link(onBit1,14212637:doWork1,[])
link(onBit2,14212637:doWork2,[])
link(onBit3,14212637:doWork3,[])
link(onBit4,14212637:doWork4,[])
}
Add(ChanelToIndex,14212637,385,399)
{
Count=4
link(onIndex,1227553:doGetString,[])
}
Add(StrList,1227553,483,357)
{
Strings=#24:Нажата левая кнопка мыши|26:Отпущена левая кнопка мыши|25:Нажата правая кнопка мыши|27:Отпущена правая кнопка мыши|
Point(doGetString)
Point(onGetString)
link(onGetString,7108463:doWork2,[])
}
Add(HubEx,7567543,574,273)
{
link(onEvent,15090687:doAdd,[])
}
Add(HubEx,7108463,574,364)
{
Angle=3
link(onEvent,7567543:doWork3,[])
}

карма: 1

1
файлы: 2win732bitrawinput.png [14.4KB] [1088], rawinputmodule.7z [1.8KB] [340]
Голосовали:login