Reading HID proxy card in Windows Store app

2019-08-14 22:55发布

问题:

I'm trying a PoC where in I'm trying to authenticate a user based on their HID card value. I don't have any specific API for the reader. The reader outputs plain number of the card by keyboard emulation.

The PoC permits a user to authenticate through username/password or through HID proxy card. To simplify things I wanted to use a hidden TextBox to which the value from HID is read and a corresponding webservice is triggered from TextChanged event.

I was unable to do so. Can anyone advice how this can be done, I'm very new to .Net environment.

回答1:

Using that version of the reader device (the one with the keyboard emulation) you will need some form of text input control (e.g. a TextBox) to capture the text that the virtual keyboard sends. The problem with your approach of using a hidden TextBox is that it won't get the focus while the virtual keyboard "types" the card ID.

So you would need to intercept the KeyDown event in whatever UI element has focus while you expect the card ID. For instance if you have an window and no TextBox (or other element that consumes KeyPress events) has the focus, you could try to intercept the KeyPress event at the window level:

<Window ...
    KeyDown="onKeyDownHandler"
>

The corresponding handler method would look like this:

private void onKeyDownHandler(object sender, KeyEventArgs e) {
    // e.Key will give you the pressed key
}

So using this handler you should be able to collect all virtual key presses that are sent by the RFID reader. So all you would need to do is collect them and translate them into characters.


UPDATE:

This product leaflet suggests that the virtual keyboard version of the reader can configured to add keystrokes before and after the card ID. So you might be able to detect and mask out the input sent from that RFID reader even if the focus is on the text input fields for username or password by adding a character/control keycode that cannot occur in a username/password before the card ID. Then you could intercept the KeyDown event in both textboxes and -- upon receiving that control keycode -- you could consume all keystrokes sent by the virtual keyboard. By marking those key strokes with e.Handled = true;, you should be able to hide them from the text boxes.

As an alternative, you could use the serial version (e.g. USB virtual COM port) of that reader. If that's an option... You could then receive card IDs over a serial connection instead of the virtual keyboard. As a result, you would easily be able to distinguish between user input and RFID reader input as both would arrive on different communication interfaces.