DermFrench DermFrench - 1 year ago 274
C# Question

WPF c# Detect which keyboard sent through a key press (to detect if it was barcode scanner)

I have a USB barcode scanner attached.
I'm currently detecting whether key presses were sent to a text box from it via keyups, by having it send a special key combination before it sends the barcode.

However I was wondering if there is another way to do it.

I took at the KeyEventArgs

private void TextBox_KeyUp(object sender, KeyEventArgs e)
this.TextBlock1.Text = e.KeyboardDevice.ToString();

I thought e.KeyboardDevice might give me some info on which "keyboard" e.g. the standard keyboard or the "usb barcode scanner keyboard" but I can't seem to find any of that information.

I just thought there may be a neater way of doing this than sending the special key combination from the barcode scanner and using that.

Properties of e.KeyboardDevice

Answer Source

I've used this answer to solve the same problem in the past. The answer contains a link with full details about the solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download