Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Is it possible to send output to a mouse and keyboard to change its channel? If so, how can I do that?

I don't have any experience in USB HID, but I used the 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 its channel. Unfortunately, without a 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

Below, I am adding the trace log after I press a key switching from the first to the 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
like image 236
Daniel Avatar asked Oct 20 '25 22:10

Daniel


2 Answers

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
  • The first item must be 10
  • [Device Index] is one-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 zero-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 information here: Device change button does not affect other connected devices #28

like image 183
Andy Blackman Avatar answered Oct 24 '25 13:10

Andy Blackman


Thanks for this helpful post! Building on Andy Blackman's post:

I managed to get this working for my setup:

Keyboard: Logitech Ergo K860

Mouse: Logitech MX Vertical

My use case is switching both my keyboard and mouse between two systems using a script. Both systems have a Logitech unifying receiver which I seemed to have better luck with than Bluetooth.


Here are the commands I used:

On my secondary system, I have a script to switch to my first system. The script runs the following commands: Swap to Channel 1 of Logitech Ergo K860 Keyboard: ./hidapitester --vidpid 046D:C52B --usage 0x0001 --usagePage 0xFF00 --open --length 7 --send-output "0x10,0x01,0x09,0x1c,0x00,0x00,0x00"

Swap to Channel 1 of MX Vertical Mouse: ./hidapitester --vidpid 046D:C52B --usage 0x0001 --usagePage 0xFF00 --open --length 7 --send-output "0x10,0x02,0x0c,0x1c,0x00,0x00,0x00"

Then on my first system, I have a script to switch to the secondary one: Swap to Channel 2 of Logitech Ergo K860 Keyboard: ./hidapitester --vidpid 046D:C52B --usage 0x0001 --usagePage 0xFF00 --open --length 7 --send-output "0x10,0x01,0x09,0x1c,0x01,0x00,0x00"

Swap to Channel 2 of MX Vertical Mouse: ./hidapitester --vidpid 046D:C52B --usage 0x0001 --usagePage 0xFF00 --open --length 7 --send-output "0x10,0x02,0x0c,0x1c,0x01,0x00,0x00"


Here's a rough breakdown of the anatomy of the --send-output part of the command (note the examples below are switching to channel 1):

Logitech Ergo K860

Header Receiver Slot ID Const/Magic Number Target Channel Padding Padding
0x10 0x01 0x09 0x1C 0x00 0x00 0x00

MX Vertical

Header Receiver Slot ID Const/Magic Number Target Channel Padding Padding
0x10 0x02 0x0C 0x1C 0x00 0x00 0x00

Some notes:

  • Receiver Slot: one-based index that corresponds to the devices paired to the Logitech unifying receiver. This will vary depending on your setup. Downloading Logitech's unifying software might help if you need to check this. Or you could try brute forcing it since there are only a maximum of six devices that can be paired to a unifying receiver.
  • ID: Finding this was the time-consuming part for me. I think this varies depending on the model/type of the Logitech device. I found this through trial and error by monitoring USB traffic. Note that the ID for the keyboard and mouse were different in my case.
  • Target Channel: zero-based index that corresponds to the channel you want the Logitech device to be swapped to.
  • Const/Magic Number: Disclaimer: I'm not entirely sure what decides this part of the message, but for my case it was 0x1C.
like image 34
JL7 Avatar answered Oct 24 '25 11:10

JL7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!