Search code examples
usbhidlibusblogitechhidapi

Send output to a device to change channel in Logitech mouse/keyboard


I have Logitech mouse and keyboard supporting switching between multiple devices. The feature I am missing is to simultaneously switch mouse AND keboard by running a command or a shortcut.

I would like to ask if it is possible to send an output to a mouse and keyboard to change it's channel? If so, could you guide me how to do that?

I have no experience in USB HID, but I used busdog tool to sniff output and I found that following code is send every time I press a key to change channel from the first to the second one.

Code:

10 03 41 04 71 8a 40

Afterwards I tried to use commandline tool called hidapitester to send the code to a keyboard hoping that it will change it's channel. Unfortunately without result.

$ hidapitester --vidpid 046D/C52B --list

046D/C52B: Logitech - USB Receiver
046D/C52B: Logitech - USB Receiver
046D/C52B: Logitech - USB Receiver
046D/C52B: Logitech - USB Receiver

Opening device, vid/pid: 0x046D/0xC52B
Closing device


$ hidapitester --vidpid 046D/C52B --open --length 7 --send-output 0x10 0x03 0x41 0x04 0x71 0x8a 0x40 --read-input

Opening device, vid/pid: 0x046D/0xC52B
Writing output report of 7-bytes...wrote -1 bytes:
 10 00 00 00 00 00 00
Reading 7-byte input report 0, 250 msec timeout...read -1 bytes:
Closing device

Update:

Below I am adding trace log after I press a key switching from first to second channel:

Id  Type                        Time        Length  Hex
24  In  (USB URB Function: 9)   0.000000    20      11 03 08 20 00 d2 01 00 00 00 00 00 00 00 00 00 00 00 00 00
29  R                           0.000377    20      11 03 08 20 00 d2 01 00 00 00 00 00 00 00 00 00 00 00 00 00
24  In  (USB URB Function: 9)   0.291648    7       10 03 41 04 71 8a 40
28  R                           0.000449    7       10 03 41 04 71 8a 40

Solution

  • The codes you captured are the result of switching (not actually the command to switch) - you need to use different codes to make it switch - as follows (Credit to @davidschreiber):

    10 [device index] 08 10 [channel index] 00 00 00
    
    • First item must be 10
    • [Device Index] is 1-based - and depends on the order your devices were registered (so trial and error is needed)
    • 08 and 10 can actually vary in a wide range - I use 09 and 11 and that also seems to work!
    • [Channel Index] is 0-based - and relates directly to 1,2,3 on the Keyboard/Mouse

    Additionally (certainly on windows) you need to specify the usage and usagePage parameters in hidapitester.

    So this works for me - switching my Mouse (Device #1 = 0x01) onto Channel 3 (0x02)

    hidapitester.exe --vidpid 046D:C52B --usage 1 --usagePage 0xFF00 --open --length 7 --send-output 0x10,0x01,0x09,0x11,0x02,0x00,0x00
    

    You can find loads more amazingly useful info here: https://github.com/Logitech/logi_craft_sdk/issues/28