Determining which keyboard is sending keystrokes

I have two keyboards connected to my machine (one on PS / 2, the other on USB). How can I determine which keyboard is sending keystrokes in C #?

+2


source to share


5 answers


Here's an example, very messy code, showing how to use Windows login credentials from .NET. Works best with the Snippet compiler:>

EDIT: turns out the length limitation for messages,



grab the source code here

...

+3


source


If you're on a USB device then you should be able to figure it out - at least at the driver level. However, up the stack, I haven't heard of such an option. I wouldn't be surprised if this is not possible at all.

One avenue you might want to check out is dance simulators. You know, those who have "dance" (or "dance floor"). These dance rugs are really nothing more than large keyboards. Check it out for yourself - open notepad and jump to the dance. :)



Now, some of these programs also offer a competitive mode where you can connect two dance mats and compete with a partner. In this case, they will need to distinguish between mats in some way - this is the same as what you are trying to do.

+2


source


My guess is that the problem is that when the barcode scanner is used, the number goes to the active field and not to the field for barcode ID?

One solution would be to intercept other "OnChange" events and look for the barcode number inserted into them (via RegEx). If found, move the barcode out of this field and move the value to the barcode field.

No device access required, it can even be done on a Javascript driven web page.

+1


source


Ok, here's a really kinky method that will only work with a very limited subset of use cases:

  • Tape, glue, or short-circuit a set of modifier keys (such as Ctrl Ctrl) on one of the keyboards.
  • Look at the modifiers each time you press a key. If the modifiers are set the same as on a glued keyboard, assume the keyboard is the source. If not, let's say it's a different keyboard.

Limitations:

  • You cannot use a glued keyboard outside of your application, as only it knows to ignore modifier keys.
  • You cannot use these modifier keys in your application as part of keyboard shortcuts.
  • Another keyboard can impersonate you (accidentally or not) if the user holds down the correct buttons.
  • You need to disable StickyKeys.
  • Using Alt or Ctrl has a downside: if you press another, Windows may use this combination that your application won't catch.

Unknown # 1 : Only ModifyKeys populates only from the keyboard that was the source of the keystroke, or comes from the sum of all modifiers on all connected keyboards. I suspect that each keyboard internally sends modifiers attached to the keystroke, and that Windows does not aggregate them.

Unknown # 2 : Whether System.Windows.Forms.Control.ModifierKeys contains only the Ctrl / Shift / Alt bits or provides enough detail to, for example, highlight the right Ctrl key from left. Here are the keys you could theoretically check, I don't know how many are provided via ModifierKeys:

http://msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx

+1


source


I think the only way you could do this is by monitoring the USB traffic. I've seen programs that do this, but I have no idea how to do it in C #. So if there is USB traffic and a key press, it is a USB keyboard. If there is no traffic, it is PS / 2.

Naturally, another caveat is that it doesn't generalize to arbitrary or future types of keyboard connections.

0


source







All Articles