2

I'm in charge of technology at my local camera club, a not-for-profit charity in Malvern UK. We have a database-centric competition management system which is home-brewed by me in Delphi 6 and now we wish to add a scoring system to it. This entails attaching 5 x cheap-and-standard USB numeric keypads to a PC (using a USB hub) and being able to programmatically read the keystrokes from each keyboard as they are entered by the 5 judges. Of course, they will hit their keys in a completely parallel and asynchronous way, so I need to identify which key has been struck by which judge, so as to assemble the scores (i.e. possible multiple keystrokes each) they have entered individually.

From what I can gather, Windows grabs the attention of keyboard devices and looks after the characer strings they produce, simply squirting the chars into the normal keyboard queue (and I have confirmed that by experiment!). This won't do for my needs, as I really must collect the 5 sets of (possibly multiple) key-presses and allocate the received characters as 5 separate variables for the scoring system to manipulate thereafter.

Can anyone (a) suggest a method for doing this in Delphi and (b) offer some guide to the code that might be needed? Whilst I am pretty Delphi-aware, I have no experience of accessing USB devices, or capturing their data.

Any help or guidance would be most gratefully received!

IanT
  • 41
  • 2
  • Windows provides [Raw Input](https://learn.microsoft.com/en-us/windows/desktop/inputdev/about-raw-input) for this purpose. Not for Delphi but shows what Raw Input can do: [Using Raw Input from C# to handle multiple keyboards](https://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard). Harder than regular input but a lot easier than USB drivers etc. – Brian Jul 23 '18 at 14:39
  • @Jerry I don't think what you said here is accurate – David Heffernan Jul 23 '18 at 15:07
  • 1
    Looks like this might be a duplicate question: https://stackoverflow.com/questions/3060512/how-to-distinguish-multiple-keyboards-in-delphi – Brian Jul 23 '18 at 15:13

1 Answers1

5

Windows provides a Raw Input API, which can be used for this purpose. In the reference at the link provided, one of the advantages is listed as:

  • An application can distinguish the source of the input even if it is from the same type of device. For example, two mouse devices.

While this is more work than regular Windows input messages, it is a lot easier than writing USB device drivers.

One example of its use (while not written in Delphi) demonstrates what it can do, and provides some information on using it:

Using Raw Input from C# to handle multiple keyboards.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Brian
  • 6,717
  • 2
  • 23
  • 31