How to: USB-to-USB keyboard/mouse filter?

Status
Not open for further replies.

gwideman

Well-known member
I'm wondering what reasonable alternatives there are for implementing a unit that functions as a USB keyboard filter or USB mouse filter. That is, the unit would have two USB ports, one that attaches to a host PC and looks like a USB keyboard or mouse (as Teensy can do easily), and the other attaches to an actual keyboard or mouse.

The goal is to implement various "filtering" features (eg: key mappings, or mouse behavior adjustments).

I've read various other threads that talk about USB shields, and/or possibly two Teensy's back-to-back via serial or whatever, but I could use clarification of the current state of the landscape in this area, such as:

-- What shield or Teensy-to-Teensy (or even Teensy-Arduino) approaches work well (in general, not just this application)?
-- What libraries are available that allow Teensy to host a USB keyboard or mouse?
-- Performance gotchas to watch for (eg: when implementing a mouse acceleration curve).

Any comments welcome! Thanks,

-- Graham
 
For keyboards:
Try having a look at TMK's github repository here: https://github.com/tmk/tmk_keyboard, and their documentation on USB keyboard report protocols in the doc/USB_NKRO.txt file here.

They have working PS/2->USB converter code for Teensy 2/2++, and an experimental USB->USB converter for an Arduino Leonard with a USB Host shield. Both provide working examples for how USB keyboards are represented to the operating system, including stuff like alternative reports to enable more than 6-key reports. (I use a teensy 2++ as a PS/2->USB converter based on the TMK converter's code with minor pin number adjustments at work every day, because my ergonomic keyboard was PS/2 and my new PC didn't have any PS/2 connections on the motherboard).

I suspect to use a Teensy 3/3.1 for USB->USB, you'll need the USB Host stuff that is on Paul's todo list (so that you can actually read the usb keyboard's keypress reports). PS/2 is much easier - the Teensy 2 code should be able to be ported to Teensy 3 without too much work, and the converters are a good start point for learning how USB keyboard reports actually work.

Other resources I'd recommend looking at would be some of the discussions on the GeekHack forums - I learned a lot from the discussions that were posted there. Hasu's TMK thread and Soarer's NKRO converter thread in particular I found were worth reading through.

For mice:
I haven't done anything with mouse converters yet, but there seems to be some converter stuff for PS/2 mice in the TMK git repository as well so I'd proably start there and move out from that.
 
Hi Dawnmist: Thanks for your reply.

Yes, having Teensy read a PS2 keyboard is surprisingly easy (library included in the Teensyduino download), and I'm assuming a PS2 mouse would be similarly easy. It's the reading of USB keyboard and mouse that's the hard part :-(.

Thanks for the pointer to the USB-to-USB converter, I will look into that. It would be great if there arises a standard approach to this, I'll have to check into Paul's USB Host efforts. Also the other links you posted.

-- Graham
 
Out of curiosity, I started having a look into tmk's code for the USB->USB converter, and following through to the original usb host library they were using. This resulted in this link: Teensy 3.0 now supported by the USB host library - so even without stuff from Paul in teensyduino (though I think he's been submitting code patches directly to this library through github, so he's still done some of the work there!) it's likely to be possible to get this going now. The library itself is linked to/used by the tmk keyboard library (which is how I found it): https://github.com/felis/USB_Host_Shield_2.0. The examples show it supporting both USB keyboard (boot-mode) report handling and mouse (boot mode) report handling, so looks like the library is providing exactly the starting blocks you were looking for. :D
 
Last edited:
Status
Not open for further replies.
Back
Top