1

I have a .net wpf form examining keystrokes using:

private void Window_PreviewKeyDown(object sender, KeyEventArgs e)

There are two 'keyboards': one is the standard input keyboard and the other is a USB credit card reader. Do any of the KeyEventArgs properties allow me to tell which Hardware ID sent the text?

Or is there a method I can call from PreviewKeyDown() to get the Hardware ID? I have looked through all the KeyEventArgs properties including the private ones I don't have access to and could find nothing specific to a Hardware ID.

user1185782
  • 53
  • 1
  • 1
  • 8
  • Not saying that it is impossible, but, in the other hand if you are reading credit cards bear in mind that they follow standards which you can stick with, for example you can validate if the incoming stream for Track1 match regular expression:^%([A-Z])([0-9]{1,19})\^([^\^]{2,26})\^([0-9]{4}|\^)([0-9]{3}|\^)([^\?]+)\?$. If that is the case I can presume the input comes from card reader. – E-Bat Feb 18 '15 at 01:33
  • 2
    Take a look at this answer http://stackoverflow.com/questions/587840/how-to-distinguish-between-multiple-input-devices-in-c-sharp – Gary Wright Feb 18 '15 at 13:49
  • I am always able to identify card reader input: it starts with – user1185782 Feb 18 '15 at 14:04
  • I want to thank Gary for steering me towards wm_input. I found an absolutely excellent article with a library for handling keyboard devices using wm_input. So I did not have to write the low-level code after all. I stopped using PreviewKeyDown at all - such a pity Microsoft could not report the sending device in one of the KeyEventArgs properties. http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard – user1185782 Feb 18 '15 at 21:12
  • Does this answer your question? [How to distinguish between multiple input devices in C#](https://stackoverflow.com/questions/587840/how-to-distinguish-between-multiple-input-devices-in-c-sharp) – FlyingFoX Aug 08 '22 at 10:46

0 Answers0