Can you daisy chain USB keyboards?

User avatar
elecplus

25 Jul 2016, 16:55

I saw a post online where a fellow plugged a mechanical USB keyboard into an Apple scissor switch USB secondary port, but he only uses the mechanical.

I have tried plugging 2 different keyboards into 2 USB sockets, but they get confused. If you press caps lock on one, it activates it on the other also.

Can you daisy chain 2 USB keyboards together (assuming the first one has a secondary USB port), and then use a hot keys program to assign different things to the keys on the 2nd board?

I have lots of keyboards to choose from, but I was thinking of using a Razer Black Widow as the primary board, and another Cherry as the secondary board. Unfortunately the only keyboards I have with a built-in "wedge" are all rubber domes :evil:
Last edited by elecplus on 25 Jul 2016, 17:27, edited 1 time in total.

User avatar
XMIT
[ XMIT ]

25 Jul 2016, 17:25

There is no true generic answer to this. The best I can offer is: "maybe, try it and see."

The USB 2.0 protocol provides for up to 500mA of current at 5V, for a total of 2.5 W of power to be sourced from a USB connector. Up to 127 devices can be daisy-chained to a single port provided the power draw from the port stays under this limit.

This specification is for root devices. Hubs and the like do not necessarily need to meet this requirement.

So, with the above two limitations, you should be able to daisy chain boards just fine.

Note that backlighting consumes a whole bunch of power. You might find that, you can normally use a Razer backlit board with a Cherry board plugged into it, but that if you turn up the backlighting on the Razer board, the Cherry board falls off the bus and acts as if it has been unplugged. IIRC Razer boards specifically use a second USB port to provide enough power for the integrated hub.

With regards to "If you press caps lock on one, it activates it on the other also": this is normal, expected behavior, but is also somewhat platform dependent. I think what you are describing is Windows specific behavior. Under Mac OS, modifiers only apply to the keyboard on which they are pressed - much to the frustration of split keyboard folks - e.g. Ergodox, keyboard.io - who need to also implement some sort of keyboard-to-keyboard protocol.

I would propose changing the thread title to: "Can you daisy chain USB keyboards?" When I read the thread title, somehow Apple Desktop Bus (ADB) was the first thing that popped into my head.

Findecanor

25 Jul 2016, 17:42

USB does not have true daisy-chaining. If a keyboard has a USB port then it actually includes a USB hub and that hub has an internal port to which the keyboard's keyboard device is connected.
So if you "daisy-chain" two keyboards then what you get is actually a USB hub with two keyboards connected to it.

As far as I have seen, both MacOS/iOS, Linux/Android/ChromeOS and Windows should treat all plugged-in keyboards as being part of a larger keyboard. For instance, you should be able to hold Shift on one keyboard and press 'a' on another and get a an upper-case 'A'.

andrewjoy

25 Jul 2016, 17:44

The original idea of USB was to have an in and out on every device and chain them but modern day USB does not do that ( its called a bus for a reason kids ).

If the USB port on the keyboard is a hub it should work , if not the HUB is not following the USB spec.

Findecanor

25 Jul 2016, 20:37

Daisy-chaining a backlit keyboard is not likely to work.
Cherry MX keyboards with backlighting tend to draw just under the max of 500 mA because of all the LEDs. The LEDs are not even all lit at the same time - if they were, it would be hard to go under 500 mA. The LEDs are instead blinking at a high rate, with one set of LEDs lit while others are dark.
There are backlit keyboards with a USB port but they tend to not have a hub but a passthrough - with two plugs on the host end of the cable.

rootwyrm

25 Jul 2016, 22:03

*cracks knuckles* Device driver experience here, including USB HID, so sit back and prepare to get confused.

First of all, USB keyboards do not have drivers. They have a standard definition called a HID - Human Interface Device. The HID standard defines things like the scan codes. Because of the way USB and the protocol is designed, any return codes (that is: a message sent to the keyboard in response to a keystroke) are duplicated to all devices using the same HID. That's why if you hit NumLock on one keyboard, it triggers on all of them - that's because the STATE has to propagate.

Code: Select all

struct kbdmux_state
{
    char             ks_inq[KBDMUX_Q_SIZE]; /* input chars queue */
    unsigned int         ks_inq_start;
    unsigned int         ks_inq_length;
    struct task      ks_task;   /* interrupt task */
    struct callout       ks_timo;   /* timeout handler */
#define TICKS           (hz)        /* rate */

    int          ks_flags;  /* flags */
#define COMPOSE         (1 << 0)    /* compose char flag */
#define POLLING         (1 << 1)    /* polling */
#define TASK            (1 << 2)    /* interrupt task queued */

    int          ks_mode;   /* K_XLATE, K_RAW, K_CODE */
    int          ks_state;  /* state */
    int          ks_accents;    /* accent key index (> 0) */
    u_int            ks_composed_char; /* composed char code */
    u_char           ks_prefix; /* AT scan code prefix */
    SLIST_HEAD(, kbdmux_kbd) ks_kbds;   /* keyboards */

    KBDMUX_LOCK_DECL_GLOBAL;
};
That's from the kbdmux(4) driver in FreeBSD. It might not be entirely obvious what it does throughout, but you can see the key points. All keyboard HIDs will poll at the same rate by necessity. Flags internally identify what keyboard types (kbdmux can mux PS/2 + USB, so it's more complicated). It shares the ks_state and the accent key index. This is true for all USB keyboards because any muxing driver must also share state across all devices, and any USB HID keyboard is automatically a muxing driver.

There is not, however, an upper limit on how many USB HID devices can be attached to a single system unless imposed by the driver implementation. e.g. kbdmux(4) can theoretically handle 256 keyboards on a single system. Why you would, who knows, but it could do it. Maybe.

However, you could not assign different keys to different boards unless one of them uses a non-HID driver explicitly. The system cannot actually differentiate between the two keyboards from an input perspective; all it ultimately knows is that a keyboard sent a keystroke. It doesn't know which, because there's no provision for it. Most backlight controllers with PC control are actually implemented as secondary USB devices on the same downstream port or an internal USB hub a la vUSB. It's a fully separate addressable device with a separate driver.
Theoretically you could do a custom HID driver that used the DEVID+VENID to distinguish a second keyboard, but you'd basically have to fully reinvent the wheel there and that's just the starting point. It wouldn't be as much difficult as very annoying and very one-off, since trying to go order of arrival will never work (it's inconsistent.)

BTW, Windows HID drivers distinguish by the upstream port - not the downstream. That's why if you install with a USB keyboard on the front panel, relocate it to a rear port and reboot, that keyboard won't work at the login screen. Which is so much more annoying than you could possibly believe. ;P

Rimrul

26 Jul 2016, 00:00

Have a look at Tom Scotts video on combining 14 keyboards into a big physical emoji keyboard: https://www.youtube.com/watch?v=lIFE7h3m40U. Not technically daisy chaining, but it's the same thing from a software perspective.

User avatar
fohat
Elder Messenger

26 Jul 2016, 16:34

rootwyrm wrote:
BTW, Windows HID drivers distinguish by the upstream port - not the downstream. That's why if you install with a USB keyboard on the front panel, relocate it to a rear port and reboot, that keyboard won't work at the login screen. Which is so much more annoying than you could possibly believe.
When you say "install" do you mean when you originally install Windows?

Could this be the reason that my Teensy-converted keyboards will not get me into BIOS at boot-up?

rootwyrm

26 Jul 2016, 17:12

fohat wrote:
rootwyrm wrote:
BTW, Windows HID drivers distinguish by the upstream port - not the downstream. That's why if you install with a USB keyboard on the front panel, relocate it to a rear port and reboot, that keyboard won't work at the login screen. Which is so much more annoying than you could possibly believe.
When you say "install" do you mean when you originally install Windows?

Could this be the reason that my Teensy-converted keyboards will not get me into BIOS at boot-up?
Yes, when you originally install Windows. But no, that is not why they do not work as BIOS. Doesn't work that way. Totally totally different issues. I would have to look more closely at the Teensy code to tell you what's up there. Could be something as silly as missing a VENID+DEVID, could be it isn't communicating in the right order. There's a literal black art to the modern PC BIOS.

Findecanor

29 Jul 2016, 02:04

Somehow I had missed this project:
USB to USB keyboard converter.

Post Reply

Return to “Keyboards”