KbQueueCheck (and related) using USB switch

To control my experiment, I have two computers running PsychToolbox simultaneously. Actually, I use four computers at my station, so to avoid clutter I have a single keyboard and mouse connected to a four-output USB switch.

Here's the MWE to explain my problem:

%%%%%%%%%%%%%%%%%

[keyboardIndices, productNames, deviceInfo] = GetKeyboardIndices;

dNum = [];
KbQueueCreate(dNum);
KbQueueStart(dNum);
while true
    keyIsDown = KbQueueCheck(dNum);
    if keyIsDown
        break;
    end;
end;
%%%%%%%%%%%%%%%%%

First, GetKeyboardIndices returns 6 items, two of which have "productNames" matching the keyboard I have connected (to be clear, there is only one keyboard, but two devices are returned for some reason. Here is the info for those devices:

>> deviceInfo{5}

ans =

  struct with fields:

     usagePageValue: 1
         usageValue: 6
          usageName: 'slave keyboard'
              index: 7
          transport: 'enabled'
           vendorID: []
          productID: []
            version: []
       manufacturer: []
            product: 'Logitech USB Keyboard'
       serialNumber: []
         locationID: 3
        interfaceID: 9
      totalElements: 251
           features: 4
             inputs: 251
            outputs: 0
        collections: 0
               axes: 3
            buttons: 248
               hats: 0
            sliders: 0
              dials: 0
             wheels: 0
    touchDeviceType: -1
     maxTouchpoints: -1

>> deviceInfo{5}

ans =

  struct with fields:

     usagePageValue: 1
         usageValue: 6
          usageName: 'slave keyboard'
              index: 7
          transport: 'enabled'
           vendorID: []
          productID: []
            version: []
       manufacturer: []
            product: 'Logitech USB Keyboard'
       serialNumber: []
         locationID: 3
        interfaceID: 9
      totalElements: 251
           features: 4
             inputs: 251
            outputs: 0
        collections: 0
               axes: 3
            buttons: 248
               hats: 0
            sliders: 0
              dials: 0
             wheels: 0
    touchDeviceType: -1
     maxTouchpoints: -1




Ok, so now suppose I set dNum = 8 and run the code I inserted near the top of this message and everything works fine (pressing a key results in breaking the loop). This will work repeatedly.

Next, I could start the loop, flip the USB switch so the keyboard is connected to the other computer, then flip the USB switch back so the keyboard is connected to the first computer. Now, unpredictably, sometimes pressing a key will not break the loop. If I force the loop to break with ctrl+c and then change dNum = 7, then the code will work again. So, which "keyboard" works has randomly switched. It doesn't switch reliably every time I flip the USB switch away and back, however: it seems random as far as I can tell. If I check the device properties after one of these switching events, I can see they are unchanged from what I posted above. Also, if I don't provide a deviceIndex when calling KbQueueCheck, it doesn't work reliably even before flipping the USB switch.

What I need is a way to get KbQueueCheck to respond reliably if I flip the USB switch away and back again. I suppose I could just check all devices with the right product name or something, but that seems suboptimal. Is there a better fix for this? Thanks in advance for any ideas.