Recent

Author Topic: Using GetRawInputDeviceList  (Read 5441 times)

dmudie

  • New member
  • *
  • Posts: 9
Using GetRawInputDeviceList
« on: November 07, 2016, 07:48:54 pm »
Good Afternoon,

I would like to use an transcriber's foot pedal (Infinity Brand) with an application I am writing.  What I have been able to find through research is that this device can be read as a Human Interface Device using RegisterRawInputDevices and GetRawInputData.  In order to get started, I am trying to get a list of devices on the Windows machine using GetRawInputDeviceList.  Unfortunately, I'm not getting it working - either when trying to return the number of devices (does not update the value), or when trying to populate an array of RAWINPUTDEVICELIST. 

Since I could not get a valid value when trying to get the device count, I hard coded 20 devices just to try and get some values into the array. 

I was a C programmer years ago... then did a lot of Delphi work.  It's been 14 or so years since I've done any work in object pascal.   With that in mind, I think the problem may have to do with pointers.  I believe that I don't have to use a pointer explicitly for iNumDevices because the function declaration looks after it with the 'var' modifier.  Please correct me if I'm wrong. 

The code is very simple because I'm simply trying to test one function.

Thank you,

David

Code: Pascal  [Select][+][-]
  1.  
  2. unit uMain;
  3.  
  4. {$mode delphi}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, jwawinuser;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Memo1: TMemo;
  18.     procedure Button1Click(Sender: TObject);
  19.   private
  20.     { private declarations }
  21.  
  22.   public
  23.     { public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.Button1Click(Sender: TObject);
  36. var
  37.       iNumDevices: LongWord;
  38.  
  39.       DeviceList : array [0..19] of RAWINPUTDEVICELIST;
  40.  
  41.       DeviceCounter:integer;
  42. begin
  43.   // get the number of devices and display them
  44.   iNumDevices := GetRawInputDeviceList(DeviceList,iNumDevices,sizeof(DeviceList));
  45.   ShowMessage(IntToStr(iNumDevices));
  46.  
  47.   // doesn't work, so I hard coded it to 20 for now
  48.   iNumDevices := 20;
  49.   iNumDevices := GetRawInputDeviceList(DeviceList,iNumDevices,sizeof(DeviceList));
  50.   ShowMessage(IntToStr(iNumDevices));
  51.  
  52.   // the contents of the array is meaningless
  53.   for DeviceCounter := 0 to 19 do
  54.      begin
  55.        Memo1.Lines.Add('Device:'+IntToStr(DeviceCounter));
  56.        Memo1.Lines.Add(IntToStr(DeviceList[DeviceCounter].dwType));
  57.        Memo1.Lines.Add(' ');
  58.      end;
  59. end;
  60.  
  61. end.
  62.                                              
  63.  



molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Using GetRawInputDeviceList
« Reply #1 on: November 07, 2016, 08:33:21 pm »
Example in Free Pascal, inspired on the msdn example:
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$MODE OBJFPC}{$H+}
  4.  
  5. uses
  6.   jwawinuser;
  7.  
  8. procedure GetList;
  9. var
  10.   nDevices    : LongWord;
  11.   listentries : Array of RAWINPUTDEVICELIST;
  12.   i           : integer;
  13. begin
  14.   WriteLn('get information about list');
  15.   if (GetRawInputDeviceList(nil, nDevices, sizeof(RAWINPUTDEVICELIST)) = 0) then
  16.   begin
  17.     WriteLn('found ', nDevices, ' devices');
  18.  
  19.     Writeln('Set size of list');
  20.     SetLength(listentries, nDevices);
  21.  
  22.     if (GetRawInputDeviceList(@ListEntries[0], nDevices, sizeof(RAWINPUTDEVICELIST)) <> LongWord(-1) ) then
  23.     begin
  24.       for i := low(ListEntries) to High(ListEntries) do
  25.       begin
  26.         WriteLn('handle = ', listentries[i].hDevice, '  Type = ', listentries[i].dwType);
  27.       end;
  28.     end
  29.     else WriteLn('error retreiving the list');
  30.  
  31.     SetLength(listentries, 0);
  32.   end
  33.   else WriteLn('error');
  34. end;
  35.  
  36. begin
  37.   GetList;
  38. end.
  39.  
« Last Edit: November 07, 2016, 08:41:06 pm by molly »

dmudie

  • New member
  • *
  • Posts: 9
Re: Using GetRawInputDeviceList
« Reply #2 on: November 07, 2016, 09:37:33 pm »
Molly:

That worked perfectly.  Thank you for your help.

David

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: Using GetRawInputDeviceList
« Reply #3 on: November 09, 2016, 10:34:44 pm »
You could use this lib, for HID:
https://github.com/LongDirtyAnimAlf/FPC-USB-HID
Both Windows and Linux.

 

TinyPortal © 2005-2018