Logitech/logi_craft_sdk

Device change button does not affect other connected devices

metrailer opened this issue Β· 71 comments

When using the device switch button on the MX Keys the MX Master 3 does not also switch devices or vice versa. Providing this option allows better swapping between devices.

Agreed, this feature would be great. Needing to lift the MX Masters 2s is a tedious process.

Also agree! I hate picking up my mouse and pushing the button every time I want to switch.

One sort-of workaround is using "Flow" to switch devices, but my experience is it still has a lot of bugs. I use the "ctrl+screen edge" option so I don't switch devices on accident by moving the mouse too far. Sometimes it will switch anyway when my mouse moves to the edge of the screen (seems to be an issue mostly when computer(s) is/are waking up). Other times it will only switch one device - mouse or keyboard - but not both. I'd say it works the way it should (move mouse to edge of screen while pressing "ctrl" key, switch mouse and keyboard to other device) about 60% of the time, which is why I usually just hit the "1", "2", or "3" button (using 3 computers) on the keyboard and would prefer to be able to just hit this key to switch my keyboard and mouse!!

The sad truth is, that it's just a neglected driver for the MX Masters 2s and the Craft keyboard. The fact that Flow allows switching of both devices to a different computer (and indeed it does this as one would expect) shows that it is possible, and that syncing mouse and keyboard switching is just not implemented in the computer's driver.

Right. All of the functionality is already there - it just needs to be utilized in the user interface. I can't imagine it would be too difficult to have a checkbox or something in the "Options" software to switch both mouse and keyboard when the 1, 2, or 3 toggle buttons are used to switch devices.

Any idea if this is a custom option that could be implemented fairly easily?

I have been doing some raw command line sniffing of the USB commands sent by the Logitech software to the unifying receiver, and could switch both Craft keyboard and MX Masters 2S mouse (which are connected using the same unifying receiver) to any other channel(1, 2, or 3).

For sniffing I used busdog: https://github.com/djpnewton/busdog
For sending raw USB commands I used USB-HID-Tool: https://github.com/OpenAcousticDevices/USB-HID-Tool

I never did USB development, or protocol decoding, so my skills are fairly low on that end, but I'm still documenting what I found out so far.

The logitech driver uses simple commands to the unifying receiver, that encode the index of the device connected to the unifying receiver (in my case 1 being the keyboard, and 2 being the mouse), as well as some commands.

For example, this is one example for a command sent to the device:

0x10 0x01 0x09 0x3a 0x00 0x00 0x00

As far as I have seen, all commands start with 0x10 as the first byte. This is followed by one byte marking the device index (in case of the example 0x01). I would have expected the index to be 0-based, but in my case it was 1-based instead. I haven't checked it for other unifying receivers or computers yet, so it might be my specific setup (connected and disconnected quite often since I have the receiver).

The next 2 bytes are different for each command. I assume that these two bytes encode the actual command, and I have been able to identify at least some commands:

Channel switching

0x0810 through 0x081f cause the receiving device to switch channel (1,2,3). The command is followed by 1 byte parameter, which encodes the channel to select using a 0-based number:

10 [device index] 08 10 [channel index] 00 00 00

I haven't figured out why Logitech uses a range of commands for switching, as I could spot no difference in behavior between any of the commands.

For example, my computer sending this command, will make my keyboard (index 2) switch to the first channel:

.\usbhidtool.exe 0x046D 0xC52B 0x10 0x02 0x08 0x10 0x00 0x00 0x00

And this command switches my keyboard to the second channel instead:

.\usbhidtool.exe 0x046D 0xC52B 0x10 0x02 0x08 0x10 0x01 0x00 0x00

(The first two arguments to the tool are the VID and PID of the USB interface or endpoint, and not part of the protocol itself.)

Here's another example, switching my mouse (index 1) to the first channel (channel index 0):

.\usbhidtool.exe 0x046D 0xC52B 0x10 0x01 0x08 0x10 0x00 0x00 0x00

When Flow switches my mouse and keyboard, among other things, it sends two commands to the unifying receiver:

10 01 08 1f 01 00 00
10 02 08 1e 01 00 00

The first one switches my mouse to channel 2 (my other computer), the second command switches my keyboard.

From everything I learned today, it should indeed be possible to write a small "driver extension" that switches devices at the same time.

Just for the sake of completeness, another command I deciphered is some kind of channel description. When sending this, the selected device will return a description of the device that is connected to the given channel:

10 02 09 3e 00 00 00

In this case, my keyboard (02) is asked to return description of channel 00 (the first byte after the 2-byte command identifier. The command identifier for this is 0x093e. In my case, the keyboard answers with this (among other stuff that follows):

Hex                                                          	Ascii	
11 02 09 3e 00 00 44 45 53 4b 54 4f 50 2d 46 53 4b 49 33 45	...>..DESKTOP-FSKI3E

That's the name of my desktop machine, which is mapped to channel 2. The first byte of the message is 11 and is always the same when any device responds to a command (seems like 10 means in and 11 means out, or such).

Did anyone solve this issue? I do have a MX Keys and a MX Vertical and i would like to switch my devices with a single touch on the mx keys button.

I haven't followed up on this after my initial experiments. While this is definitely just a driver issue (or at least can be easily fixed via the driver) it doesn't seem Logitech has scheduled any work on fixing this for the higher end product lineup right now.

@davidschreiber
I followed your instruction and in my case keyboard switch to second channel has following hex number:

10 02 41 04 71 61 40

unfortunately while I am trying to send the command using USB-HID-Tool:

usbhidtool 0x046D 0xC52B 0x10 0x02 0x41 0x04 0x71 0x61 0x40

I receive following errors:

ERROR: device not connected

and on my second laptop:

ERROR: incorrect response from the device

Could you please tell me what I am doing wrong?

Have you complied USB-HID-Tool using Microsoft Visual C++ Build Tools or just used pre-compiled usbhidtool.exe files downloaded from Github repository?

@davidschreiber
I followed your instruction and in my case keyboard switch to second channel has following hex number:

10 02 41 04 71 61 40

unfortunately while I am trying to send the command using USB-HID-Tool:

usbhidtool 0x046D 0xC52B 0x10 0x02 0x41 0x04 0x71 0x61 0x40

I receive following errors:

ERROR: device not connected

and on my second laptop:

ERROR: incorrect response from the device

Could you please tell me what I am doing wrong?

Have you complied USB-HID-Tool using Microsoft Visual C++ Build Tools or just used pre-compiled usbhidtool.exe files downloaded from Github repository?

Have the same issue, on both mac and windows. Would be nice to know how to make it work. Thx!

9000h commented

Hi,
nice research but Logitech should give the community a hand and should soon add at least Linux support as they advertise it but there is nothing like options or flow.
I was under the impression there is proper support for Linux and now I found out the mx keys/craft do not really fit my needs.
CU

@dnlw07 and @vladubogdan

usbhidtool 0x046D 0xC52B 0x10 0x02 0x41 0x04 0x71 0x61 0x40
The second and third part: 0x046D 0xC52B relate to your devices VID and PID.
You will need to work these out on your computer and change them.
I know it's not a full explanation of finding your VID PID:
https://interworks.com/blog/ijahanshahi/2014/07/18/identify-vid-pid-usb-device/#:~:text=Identify%20the%20PID%20VID%20of%20a%20USB%20Device&text=Under%20the%20Property%20drop%2Ddown,be%20displayed%20on%20the%20screen.

Thank you @davidschreiber

@Devod-co-uk

thanks for the tip. I have checked PID and VID and actually are the same values in my case.

I used different tool called hidapitester (instead of USB-HID-Tool proposed by @davidschreiber).
Now I am able to connect the MX keyboard and send the output, however the command does not switch the channel.

command I send:

hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x1c,0x01,0x00,0x00

output I receive:

Opening device, vid/pid: 0x046D/0xC52B
Writing output report of 7-bytes...wrote -1 bytes:
 10 03 41 04 71 8A 40
Closing device

I also wrote a python script, but also without result:

import hid
import time


# try opening a device, then perform write and read
try:
    # print("\nOpening the device:")

    h = hid.device()
    h.open(0x046D, 0xC52B) # VendorID/ProductID

    print("Manufacturer: %s" % h.get_manufacturer_string())
    print("Product: %s" % h.get_product_string())
    # print("Serial No: %s" % h.get_serial_number_string())

    # enable non-blocking mode
    h.set_nonblocking(1)

    # write some data to the device
    print("\nWrite the data")

    code = [10, 3, 41, 4, 71, 61, 40]

    h.write(code)

    # wait
    time.sleep(0.05)

    # read back the answer
    print("\nRead the data:")
    while True:
        d = h.read(64)
        # d = h.read(20)
        if d:
            print(d)
        else:
            break

    print("Closing the device")
    h.close()

except IOError as ex:
    print(ex)


Is anyone who also tried to play with that?

@dnlw07 have played with it for a couple of hours. Finally got a script that switches between two devices using a Logitech Unifying adapter (I think it can be done via bluetooth connection as well).

It was done by sending the hex data I've got from Solaar change-host execution for each host-device combinations (e.g. switch keyboard from first to second device and vice versa).

@altvnv
contrgratulations!

Unfortunately I am still struggling with it.
Would you mind to share your script here, please?

Did you write a python script or used a command line tool?

@dnlw07 I don't think it can be done with the same hex values, but let's give it a try.

import hid

def change_device(hidapi_device):
    switch_keyboard_from_1_to_2 = b"\x11\x02\x09\x1C\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    switch_mouse_from_1_to_2 =    b"\x11\x01\x0A\x1B\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

    hidapi_device.write(switch_keyboard_from_1_to_2)
    hidapi_device.write(switch_mouse_from_1_to_2)

    # that's for another host
    # switch_keyboard_from_2_to_1 = b"\x11\x02\x0A\x1B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    # switch_mouse_from_2_to_1 =    b"\x11\x01\x09\x1C\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

    # hidapi_device.write(switch_keyboard_from_2_to_1)
    # hidapi_device.write(switch_mouse_from_2_to_1)

# As sometimes I've got 'no device found' errors
# let's just try to execute it 9 times and exit on first success
for i in range(1, 10):
    try:
        h = hid.Device(0x046D, 0xC52B)
        print("Manufacturer: %s" % h.manufacturer) # Just to ensure that it's using proper device
        h.nonblocking = 1
        change_device(h)
    except Exception:
        continue
    break

Hope it helps you

Thanks a lot for the snippet!

Could you tell me which lirbary are you using?

pip install hidapi
pip install hid

Both of them are very simillar and its a bit confusing.

@dnlw07 hid

pip install hid

Let me know if this snippet will do a trick for you as for the next iteration I want to try to customize the driver part.

And note that it was done with two transmitters. I have no idea whether it works using the regular bluetooth connection.

@altvnv

I am also using the same library as you.

I am able to open the device:

import hid
h = hid.Device(0x046D, 0xC52B)
h.nonblocking = 1

however I receive an error while using write method:

hex_code = b"\x10\x03\x41\x04\x71\x8a\x40"
h.write(hex_code)

the error message:

hid.HIDException: Access is denied.

Did you face similar error before?

I am pretty sure it also works via Bluetooth. The codes will be different.

P.S. Are you using Linux or you were able to install Solaar on WSL2?

@dnlw07 I'm used Linux only to obtain the proper commands for host changing feature.

According to the issue - haven't faced it but try to remove hiadpi library from your machine and download hiadpi library from official reference and import it directly from python.

import ctypes

ctypes.cdll.LoadLibrary("path\\to\\the\\dll")

....

Btw, I've done it in following way:

  1. Connected first transmitter to Linux machine
  2. Obtained commands for switching from first device to second
  3. Did it for the second transmitter

P.S. I've tried this script on Linux, Mac and Windows - everything works fine for me.

Hey folks, been trying to get this working as well. Thanks to the awesome information shared above and a bit of trial and error, I have two commands that switch my mouse and keyboard from the receiver in my laptop to the receiver in my desktop, and vice versa. They are:

Mouse 1 -> 2

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x04,0x09,0x11,0x01,0x00,0x00

Keyboard 1 -> 2

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x11,0x01,0x00,0x00

Mouse 2 -> 1

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x02,0x09,0x11,0x00,0x00,0x00"

Keyboard 2 -> 1

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x01,0x09,0x11,0x00,0x00,0x00"

This makes sense to me because the only difference is the device index. However, I have another mouse that's also synced to both of these receivers, and it seems no value in the device index updates that mouse. It is an MX Anywhere 3. Has anyone encountered any similar behavior?

Thanks!

@arjunchhabra
Hello,
regarding your question, here is the hex code for MX 3 mouse via bluetooth (source: pwr-Solaar/Solaar#1154 (comment)):
11 01 0A 1E 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

@altvnv used Solaar linux driver to get exact codes for his Logitech devices. Maybe you can try do the same if you have linux distro installed on your machine.

Here is also the documentation to HID++ 2.0 protocol:
https://github.com/Logitech/cpg-docs/tree/master/hidpp20

It may help you to figure out the hex codes. However the documentation is not easy to understand, because of missing examples.

P.S. Could you please add information to your post what keyboard and mouse are you using?
Could also you please post an output received of the commands you are using?

Figured it out! I realized the values I was capturing the values from busdog incorrectly.

What I was doing:

  • Running Busdog and capturing values received while a connected device (mouse or keyboard) pressed their device switched key

What I should have been doing (and what worked):

  • Running Busdog and capturing the values emitted while a connected device is told by Flow to switch devices

Capturing the output from my computer in the second scenario and then running that with the hidapitest executable provided the desired results and makes sense from a conceptual standpoint. For reference, I have tested this across my MX Keys, MX Anywhere (3) and M585. I will share the commands used for posterity, though the hex values seem to differ for all.

MX Anywhere 1 -> 2

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x01,0x0a,0x1a,0x01

MX Keys 1 -> 2

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x11,0x01,0x00,0x00

M585 1 -> 2

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x04,0x09,0x11,0x01,0x00,0x00

MX Anywhere 1 -> 3

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x01,0x0a,0x1a,0x02

MX Keys 1 -> 3

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x11,0x02,0x00,0x00


MX Anywhere 2 -> 1

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x0a,0x1a

MX Keys 2 -> 1

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x01,0x09,0x11,0x00,0x00,0x00"

M585 2 -> 1

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x02,0x09,0x11,0x00,0x00,0x00"

MX Anywhere 2 -> 1

./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x0a,0x1a,0x02

MX Keys 2 -> 3

~Scripts/hidapitester --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x01,0x09,0x11,0x02,0x00,0x00"

@arjunchhabra thank you for your commands!

I also faced simillar issue with BusDog showing different hex codes for changing channel by using flow vs pressing physical button.

I also have MX Keys keyboard . BusDog is showing the same hex codes while using flow switch channel method.
However in my case the command is not working :(

Command I am using for MX Keys keyboard to change channel from 1 -> 2:

hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x11,0x01,0x00,0x00

Output I receive:

Opening device, vid/pid: 0x046D/0xC52B
Writing output report of 7-bytes...wrote -1 bytes:
 10 01 09 11 02 00 00
Closing device

Could you tell mi if you have the same output as me or different?

Hey @dnlw07, I see the same output, though sometimes it says "wrote -1 bytes" and sometimes where it writes "wrote 7 bytes". I believe only the one where it says "wrote 7 bytes" are successful writes. In any case, I keep it in a loop and within a few executions it successfully switches devices. I would recommend giving that a shot!

twau commented

Thanks everyone, I can finally switch seamlessly between my Linux machine/Windows laptop. I cant understand why Logitech have not implemented this in their own software, makes everything so much better.

Linux machine is using solaar rule to switch both mouse and keyboard at the same time.
Solaar sends:
MX Keys from 1 to 2: 11 01 091E 01000000000000000000000000000000
MX Master 3 from 1 to 2: 11 02 0A1C 01000000000000000000000000000000

Windows machine, a .bat file executing:
MX Keys from 2 to 1:
hidapitester.exe --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x02,0x09,0x11,0x00,0x00,0x00"
MX Master 3 from 2 to 1:
hidapitester.exe --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x01,0x0a,0x11,0x00,0x00,0x00"

MX Keys from 1 to 2:
hidapitester.exe --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x01,0x09,0x11,0x01,0x00,0x00"
MX Master 3 from 1 to 2:
hidapitester.exe --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x02,0x0a,0x11,0x01,0x00,0x00"

Hmm I am struggling with that for two months now and still not sure if I am doing sth wrong.

  1. First I downloaded BusDog: http://daniel.net.nz/d/busdog_0.2.2/busdog_x64.exe and used it to sniff hex codes using Logitech Flow fucntionality
  2. Then downloaded prebuild library for hidapi from: https://github.com/libusb/hidapi/releases/download/hidapi-0.10.1/hidapi-win.zip and prebuild package for hidapitester from: https://github.com/todbot/hidapitester/releases/download/0.2/hidapitester-windows-x86_64.zip
  3. I put everything to the same directory, opened the command line and typed
cd %userprofile%\Desktop\hidapitester

# Flow Master 2S mouse switch 1 --> 2
hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x01,0x09,0x1c,0x01,0x00,0x00

# Flow MX Keys keyboard switch 1 --> 2
hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x1c,0x01,0x00,0x00

Nothing is working. I repeated with my second laptop with the same result.
Any idea what could go wrong here?

Did someone succeed with keyboard keys (1,2,3 device) rebinding? Is it possible without any driver customisation?

So I'm using linux as well...but oddly my gui for Solaar isn't giving me the change host options. I'm trying to figure out the command line, but not quite sure how the command should go. Incidentally, I think that has help me understood what the hex code actually represents...or at least why hex codes are not transferring well from one user to another, it looks like they might include the computer name in them (in the output of the solar CLI here under CHANGE HOST you see my computer name which is "tincan"):

 2: MX Master 3 Wireless Mouse
     Device path  : /dev/hidraw2
     WPID         : 4082
     Codename     : MX Master 3
     Kind         : mouse
     Protocol     : HID++ 4.5
     Polling rate : 8 ms (125Hz)
     Serial number: C60AEF9C
     Model ID:      B02340820000
     Unit ID:       C60AEF9C
        Bootloader: BOT 95.01.B0015
          Firmware: MPM 19.01.B0015
             Other: 
     The power switch is located on the base.
     Supports 35 HID++ 2.0 features:
         0: ROOT                   {0000}   
         1: FEATURE SET            {0001}   
       ....
         9: REPROG CONTROLS V4     {1B04}   
            Key/Button Actions (saved): {'195': 195, '196': 196, '80': 80, '81': 81, '82': 82, '83': 83, '86': 86}
            Key/Button Actions        : {'80': 80, '81': 81, '82': 82, '83': 83, '86': 86, '195': 195, '196': 196}
        10: CHANGE HOST            {1814}   
            Change Host        : 2:tincan
        11: XY STATS               {2250}   
       ...

Did any of you linux people use the CLI to swtich? I'm having trouble figuring out how to use the config command.

twau commented

So I'm using linux as well...but oddly my gui for Solaar isn't giving me the change host options. I'm trying to figure out the command line, but not quite sure how the command should go. Incidentally, I think that has help me understood what the hex code actually represents...or at least why hex codes are not transferring well from one user to another, it looks like they might include the computer name in them (in the output of the solar CLI here under CHANGE HOST you see my computer name which is "tincan"):

 2: MX Master 3 Wireless Mouse
     Device path  : /dev/hidraw2
     WPID         : 4082
     Codename     : MX Master 3
     Kind         : mouse
     Protocol     : HID++ 4.5
     Polling rate : 8 ms (125Hz)
     Serial number: C60AEF9C
     Model ID:      B02340820000
     Unit ID:       C60AEF9C
        Bootloader: BOT 95.01.B0015
          Firmware: MPM 19.01.B0015
             Other: 
     The power switch is located on the base.
     Supports 35 HID++ 2.0 features:
         0: ROOT                   {0000}   
         1: FEATURE SET            {0001}   
       ....
         9: REPROG CONTROLS V4     {1B04}   
            Key/Button Actions (saved): {'195': 195, '196': 196, '80': 80, '81': 81, '82': 82, '83': 83, '86': 86}
            Key/Button Actions        : {'80': 80, '81': 81, '82': 82, '83': 83, '86': 86, '195': 195, '196': 196}
        10: CHANGE HOST            {1814}   
            Change Host        : 2:tincan
        11: XY STATS               {2250}   
       ...

Did any of you linux people use the CLI to swtich? I'm having trouble figuring out how to use the config command.

solaar config "MX Master 3" change-host should give you all possible values/hosts
For example I can change with:
solaar config "MX Master 3" change-host 2
or
solaar config "MX Master 3" change-host higher

Thanks to everyone who has contributed here. I scrapped together this python script that just uses hidapi which is bound to a mouse button for switching between my work laptop (osx) and home machine (win) (it also switches my "monitor" input). Both use the unifying receivers as I had issues with BLE and hidapi on OSX. There is definitely some weirdness between the various OSs so hopefully this helps others.

import asyncio
from aiopylgtv import WebOsClient
import hid

def switch_mouse_and_keys():
    mx3_code = [0x11,0x01,0x0A,0x18,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
    keys_code = [0x10,0x02,0x09,0x11,0x01,0x00,0x00]
    try:
        # Find logitech receiver devices/usages
        for d in hid.enumerate(0x046D, 0xC52B):
            # Not sure why but this is the usage page that works on windows (only 1 usage 1 on OSX)
            if d['usage'] == 1 and d['usage_page'] == 0xFF00:
               write_to_device(d['path'], keys_code)
            # usage 2 = mouse - osx lets you write to usage 1 for both... not in windows
            if d['usage'] == 2 and d['usage_page'] == 0xFF00:
               write_to_device(d['path'], mx3_code)
    except IOError as ex:
        print(ex)

def write_to_device(path, data):
        print('Opening path...', path)
        h = hid.device()
        h.open_path(path)
        h.set_nonblocking(1)
        print("... opened, writing...")
        h.write(data)
        print("...write complete. Closing.")
        h.close()

async def runloop():
    client = await WebOsClient.create('192.168.1.150')
    print("Connecting to TV...")
    await client.connect()
    print("... connected, switching input...")
    ret = await client.set_input("HDMI_4")
    print("... switched. Disconnecting.")
    await client.disconnect()

asyncio.get_event_loop().run_until_complete(runloop())
switch_mouse_and_keys()

Hi guys, just want to understand how to switch my mouse mx keys automatically after the keyboard is switched>?

Hi guys, just want to understand how to switch my mouse mx keys automatically after the keyboard is switched>?

As you cannot re-map the host switch keys (well not without Solaar AFAIK) and monitoring the keyboard for those special keypresses is a PITA I'd suggest you remap another key combo or mouse button to run the script/commands (see above) to switch both the keyboard and mouse.

If you really want to stick with the host switch keys, you'd need to write something to monitor the HID input from the keyboard, detect each keypress and then execute the appropriate mouse switch as per above... if you're in Linux you may be able to use Solaar, if not you could use its source as inspiration: https://github.com/pwr-Solaar/Solaar

@rhapgood thank you for you code snippet.

Thanks your code I was able to figure out that in my case the problem was that usage and usagePage was not declared.
After applying your tips the commands are working fine.

Here are my commands to switch for Master 2S mouse and MX Keys keyboard on Windows 10. Mouse and keyboard connected via Unifying receiver.

Master 2S:

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

MX keys:

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

Unfortunately I have noticed that from time to time (20% chance that it happens) the mouse get confused and doesn't switch the channel properly.
Anyone of you faced similar issue?

Hi guys, just want to understand how to switch my mouse mx keys automatically after the keyboard is switched>?

As you cannot re-map the host switch keys (well not without Solaar AFAIK) and monitoring the keyboard for those special keypresses is a PITA I'd suggest you remap another key combo or mouse button to run the script/commands (see above) to switch both the keyboard and mouse.

If you really want to stick with the host switch keys, you'd need to write something to monitor the HID input from the keyboard, detect each keypress and then execute the appropriate mouse switch as per above... if you're in Linux you may be able to use Solaar, if not you could use its source as inspiration: https://github.com/pwr-Solaar/Solaar

thanks for response. ive got 3 PΠ‘ on Windows. so i want to switch my craft keyboard and mx master 3 simultaneously between this PC, pressing only special 1 2 or 3 buttons on keyboard.

i see some scripts, but what to understand, how to run this scripts when i pressing 1/2/3 buttons on keybord?

UPD: tried this|: MX Master 3 from 2 to 1:
hidapitester.exe --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x01,0x0a,0x11,0x00,0x00,0x00"

but no successfully

Opening device, vid/pid: 0x046D/0xC52B
Writing output report of 7-bytes...wrote 7 bytes:
10 01 0A 11 00 00 00
Closing device

@nikitozeg
Switch keys like FN, power, sleep keys are are implemented in firmware and are not recognized by OS.
I am afraid it not possible to write such script.

@dnlw07
yes but as i understand, people here switches their logitech keyboard and mouses pressing on only 1 button.

C:\1>hidapitester.exe --vidpid 046D:C52B --usage 1 --usagePage 0xFF00 --open --length 7 --send-output 0x10,0x01,0x09,0x1c,0x00,0x00,0x00
Opening device, vid/pid:0x046D/0xC52B, usagePage/usage: FF00/1
Device opened
Writing output report of 7-bytes...wrote 7 bytes:
 10 01 09 1C 00 00 00
Closing device

i tried your script but nothing changed. keyboard and mouse doesn't switched. may be it's because i have logitech craft with mx master 3

the only command that working for me, and switches my keyboard from channel 2- to 1 is:

usbhidtool.exe 0x046D 0xC52B 0x10 0x01 0x08 0x10 0x00 0x00 0x00

Help 😱

Apologize in advance for the long post... really need this feature..
I'm not sure what I'm doing wrong but can't get my devices to switch. Here is my setup details.

I have a Logitech MX-Keys and a Master-3. Both are connected to a Linux Desktop (Ubuntu 20.04) and a Macbook Pro (BigSur). I have 2 unifying devises, one for each machine. On the Linux able to switch using Solaar and that works!
I use channel 1 (on MX-Key & MS-3) to connect to the Linux desktop and Solar is configured to switch both devices to channel 2 and connect to the second unifying device on the Mac.
Now my pickle is with the Mac config πŸ€¦πŸΎβ€β™‚οΈ... can't get that to work
I've followed all the input here but still not able to get both device to switch to channel 1 from the Mac.
I followed this implementation and got the hidapi running.
I'm capturing the Hex values for each device when switching from each system. L --> M and M --> L
Hex values from Linux ---> Mac:
`
Reading 64-byte input report 0, 250 msec timeout...read 7 bytes:

MOUSE ==>10 02 41 04 B1 8A 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 02 04 00 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 02 09 1F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 02 07 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Reading 64-byte input report 0, 250 msec timeout...read 7 bytes:
KEYBOARD ==> 10 01 41 04 B2 82 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 01 04 00 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 01 08 00 32 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 0 bytes:
Reading 64-byte input report 0, 250 msec timeout...read 0 bytes:
`

Hex values from Mac --> Linux :
INFO [ReceiverListener:hidraw1] solaar.listener: connection Notification**(10,1,41,04,A28240)** for <Device(1,4082,MX Master 3 Wireless Mouse,7DD04C60)> (mouse) INFO [ReceiverListener:hidraw1] solaar.listener: connection Notification**(10,2,41,04,A18A40)** for <Device(2,408A,MX Keys Keyboard,2F35D351)> (keyboard) INFO [ReceiverListener:hidraw1] solaar.listener: status_changed <UnifyingReceiver(/dev/hidraw1,27)>: present, 2 paired devices. (0) INFO [ReceiverListener:hidraw1] logitech_receiver.status: <Device(2,408A,MX Keys Keyboard,2F35D351)> pushing device settings [<Setting([feature:toggle] MX K INFO [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(2,408A,MX Keys Keyboard,2F35D351)>: DJ connection: True Notification(20,2,42,00,0000000000000000000000) INFO [ReceiverListener:hidraw1] solaar.listener: status_changed <Device(2,408A,MX Keys Keyboard,2F35D351)>: paired online, {'BATTERY LEVEL': NamedInt(90, 'full'), 'LINK INFO [ReceiverListener:hidraw1] solaar.listener: status_changed <Device(1,4082,MX Master 3 Wireless Mouse,7DD04C60)>: paired online, {'BATTERY LEVEL': 50, 'LINK ENCRYPTED': True, 'BATTERY STATUS': NamedInt(0, 'discharging'), 'BATTERY CHARGING': False, 'BATTERY VOLTAGE': None, 'BATTERY NEXT LEVEL': 20, 'ERROR': None} (0) INFO [ReceiverListener:hidraw1] solaar.listener: status_changed <Device(1,4082,MX Master 3 Wireless Mouse,7DD04C60)>: paired online, {'BATTERY LEVEL': 50, 'LINK ENCRYPTED': True, 'BATTERY STATUS': NamedInt(0, 'discharging'), 'BATTERY CHARGING': False, 'BATTERY VOLTAGE': None, 'BATTERY NEXT LEVEL': 20, 'ERROR': None} (0) INFO [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,4082,MX Master 3 Wireless Mouse,7DD04C60)>: DJ connection: True Notification(20,1,42,00,0000000000000000000000)

Here are the commands I'm running
HID-2021-07-09_02-36

I also granted access to vs-code to my accessibility privacy setting it complained at first.
From one of the post there was a call out about using --usage and --usagePage but didn't work in my case.
I'm getting the ..'wrote 7' making me believe it applied the command but the device does not switch
Also while listing the device details using --list-detail I see that all the devices on --usagePage FF00 are using the same Path in my case, so I can't tell the difference between the MX-K and MS-3 not sure if that might be the issue.
Any pointers πŸ™πŸΎ

Help 😱

Apologize in advance for the long post... really need this feature..
I'm not sure what I'm doing wrong but can't get my devices to switch. Here is my setup details.

I have a Logitech MX-Keys and a Master-3. Both are connected to a Linux Desktop (Ubuntu 20.04) and a Macbook Pro (BigSur). I have 2 unifying devises, one for each machine. On the Linux able to switch using Solaar and that works!
I use channel 1 (on MX-Key & MS-3) to connect to the Linux desktop and Solar is configured to switch both devices to channel 2 and connect to the second unifying device on the Mac.
Now my pickle is with the Mac config πŸ€¦πŸΎβ€β™‚οΈ... can't get that to work
I've followed all the input here but still not able to get both device to switch to channel 1 from the Mac.
I followed this implementation and got the hidapi running.
I'm capturing the Hex values for each device when switching from each system. L --> M and M --> L
Hex values from Linux ---> Mac:
`
Reading 64-byte input report 0, 250 msec timeout...read 7 bytes:

MOUSE ==>10 02 41 04 B1 8A 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 02 04 00 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 02 09 1F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 02 07 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Reading 64-byte input report 0, 250 msec timeout...read 7 bytes:
KEYBOARD ==> 10 01 41 04 B2 82 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 01 04 00 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 20 bytes:
11 01 08 00 32 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte input report 0, 250 msec timeout...read 0 bytes:
Reading 64-byte input report 0, 250 msec timeout...read 0 bytes:
`

Hex values from Mac --> Linux :
INFO [ReceiverListener:hidraw1] solaar.listener: connection Notification**(10,1,41,04,A28240)** for <Device(1,4082,MX Master 3 Wireless Mouse,7DD04C60)> (mouse) INFO [ReceiverListener:hidraw1] solaar.listener: connection Notification**(10,2,41,04,A18A40)** for <Device(2,408A,MX Keys Keyboard,2F35D351)> (keyboard) INFO [ReceiverListener:hidraw1] solaar.listener: status_changed <UnifyingReceiver(/dev/hidraw1,27)>: present, 2 paired devices. (0) INFO [ReceiverListener:hidraw1] logitech_receiver.status: <Device(2,408A,MX Keys Keyboard,2F35D351)> pushing device settings [<Setting([feature:toggle] MX K INFO [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(2,408A,MX Keys Keyboard,2F35D351)>: DJ connection: True Notification(20,2,42,00,0000000000000000000000) INFO [ReceiverListener:hidraw1] solaar.listener: status_changed <Device(2,408A,MX Keys Keyboard,2F35D351)>: paired online, {'BATTERY LEVEL': NamedInt(90, 'full'), 'LINK INFO [ReceiverListener:hidraw1] solaar.listener: status_changed <Device(1,4082,MX Master 3 Wireless Mouse,7DD04C60)>: paired online, {'BATTERY LEVEL': 50, 'LINK ENCRYPTED': True, 'BATTERY STATUS': NamedInt(0, 'discharging'), 'BATTERY CHARGING': False, 'BATTERY VOLTAGE': None, 'BATTERY NEXT LEVEL': 20, 'ERROR': None} (0) INFO [ReceiverListener:hidraw1] solaar.listener: status_changed <Device(1,4082,MX Master 3 Wireless Mouse,7DD04C60)>: paired online, {'BATTERY LEVEL': 50, 'LINK ENCRYPTED': True, 'BATTERY STATUS': NamedInt(0, 'discharging'), 'BATTERY CHARGING': False, 'BATTERY VOLTAGE': None, 'BATTERY NEXT LEVEL': 20, 'ERROR': None} (0) INFO [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,4082,MX Master 3 Wireless Mouse,7DD04C60)>: DJ connection: True Notification(20,1,42,00,0000000000000000000000)

Here are the commands I'm running
HID-2021-07-09_02-36

I also granted access to vs-code to my accessibility privacy setting it complained at first.
From one of the post there was a call out about using --usage and --usagePage but didn't work in my case.
I'm getting the ..'wrote 7' making me believe it applied the command but the device does not switch
Also while listing the device details using --list-detail I see that all the devices on --usagePage FF00 are using the same Path in my case, so I can't tell the difference between the MX-K and MS-3 not sure if that might be the issue.
Any pointers πŸ™πŸΎ

FIGURED IT OUT ==> Setup is working has expectedπŸ‘πŸΎ

I'd be grateful for advice if anyone can give it.. although I suspect I'm being dumb..

I have MX Keys and MX Master 3 connected to 3 machines - PC1, PC2 and Mac, on channels 1, 2 and 3 (all using unifying receiver)

On PC1, I wrote a small C# app that uses the HID API to monitor for the keyboard switching channels from pressing the [1], [2] or [3] keys. Depending on the message received, I can then trigger the mouse to move to the desired channel.

This works perfectly when switching away from the PC where this program is running, but it doesn't work when trying to switch back.

Am I right in assuming that I need to run my app on each of the machines ?? i.e. once control is passed to a different unifying receiver, is that machine the only one that can command the mouse to move to another channel?

I would say yes. Once the keyboard & mouse have moved from device X to device Y, they have moved fully over to communicate with device Y. Device X can no longer listen to the mouse or keyboard.
Running your app on each device will allow the device to switch the mouse to follow the keyboard.
My own thoughts on this were that it would ideally be done in the Unify device firmware. i.e. not relying on any software running on the PC/Mac/Linux/etc.

I now have an exe running on my PC, listening forever for the [3] button to be pressed on my MX Keys.
On detecting this - it switches my mouse to channel 3 and EUREKA! it works.

I'm now trying to replicate the same code on my Mac (Channel 3) - but having a very weird issue... it doesn't report the keypress immediately :( i.e.

  • Keyboard is already on channel 3
  • I press [1] ... nothing reported
  • I press [3] ... and it reports the 2 events

I'm using libusb/hidapi

I've tried using hidapitester on the Mac - and see the same effect:
hidapitester --vidpid 046d:c52b --open --read-input-forever

Any thoughts ??

@arblackman can you share your code in a github project?

@krudos - my code is awful hacking right now ... I'd be ashamed to post to GH :)

However, the code is insanely simple - as follows:

This is C#, using HidSharp library

      `static void Main(string[] args)
       {
        //Per @davidschreiber : 10 [device index] 08 10 [channel index] 00 00 
        var mouseTo3 = new byte[] { 0x10, 0x02, 0x09, 0x1c, 0x02, 0x00, 0x00 }; 

        HidDevice device;
        var success = DeviceList.Local.TryGetHidDevice(out device, 0x046D, 0xC52B); // All Unifying receivers seem to be 046D:C52B
        if (success)
        {
            HidStream stream;
            if (!device.TryOpen(out stream)) { Console.WriteLine("Failed to open device."); Environment.Exit(2); }

            using (stream)
            {
                stream.ReadTimeout = 1000;
                while (true)
                {
                    var bytes = new byte[device.GetMaxInputReportLength()];
                    int count;

                    try
                    {
                        //Listen for inputs
                        count = stream.Read(bytes, 0, bytes.Length);
                    }
                    catch (TimeoutException)
                    {
                        Console.Write(".");
                        continue;
                    }

                    if (count > 0)
                    {
                        //Received a message
                        if (bytes[4] == 0x71)
                        {
                            Console.Write("[3] Pressed");
                            stream.Write(mouseTo3);
                        } 
                        else if (bytes[4] == 0xb1)
                        {
                            Console.WriteLine("[1] Pressed");
                            stream.Write(mouseTo1); //Doesn't work - just for INFO
                        }
                    }
                }
            }
        }
    }



Hello all,

After some trials I managed to make switch from Device1 to Device2.
But reverse (From Bluetooth Device2 to Device 1) , I get this error :
image
I put another Logitech Receiver into second computer and and I got rid of the error:
image
.. I tried with many variations of second parameter , but .. without success. I think the second dongle of second PC doesn't communicate with the keyboard and mouse.

Is it something I do wrong or I missed something ?

Thank you arblackman for quick response :)

But , let me explain my situation.I am conected with MX3 mouse to PC2 via Bluetooth(I dont have a dongle inserted into PC2), and next, I want to send a command to the dongle .
This command will change the device back from PC2 to PC1, and it looks like :
"hidapitester.exe --vidpid 046D:C52B --usage 1 --usagePage 0xFF00 --open --length 7 --send-output "0x10,0x01,0x09,0x1c,0x00,0x00,0x00"

Unfortunately , I get an error like
image
Ps: hidapitester.exe can be downloaded from here
https://github.com/todbot/hidapitester/releases

My question is : why this error uccurs ? And how you can get rid of this error if you know ? :D .
I see here , there are people which executed command succesfully from device2 and device1 and don't understand how is that possible :)

Awesome detectives here :)
I would love to see Logitechs helping hand here...

I have a slightly different setup, using a Logitech M720 mouse and a K850 keyboard (sold as the MK850 mouse/keyboard set). They're both connected to System 1 using a single Logitech unifying receiver and System 2 using Bluetooth. Both systems are running Windows 10. The Bluetooth side requires long HID++ commands to initiate switching, which I figured out using this article: pwr-Solaar/Solaar#1154. So, my commands turned out to be these:

Switch keyboard from System 1 to System 2:
.\hidapitester.exe --vidpid 046D:C52B --usage 1 --usagePage 0xFF00 --open --length 7 --send-output 0x10,0x01,0x08,0x11,0x01,0x00,0x00

Switch mouse from System 1 to System 2:
.\hidapitester.exe --vidpid 046D:C52B --usage 1 --usagePage 0xFF00 --open --length 7 --send-output 0x10,0x02,0x09,0x11,0x01,0x00,0x00

Switch keyboard from System 2 to System 1:
.\hidapitester.exe --vidpid 046D:B34D --usage 0x0202 --usagePage 0xFF43 --open --length 19 --send-output 0x11,0x00,0x08,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

Switch mouse from System 2 to System 1:
.\hidapitester.exe --vidpid 046D:B015 --usage 0x0202 --usagePage 0xFF43 --open --length 19 --send-output 0x11,0x00,0x09,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

The above mouse commands always work fine, and the command for switching the keyboard to System 2 always works fine too, but I'm having some problems with the keyboard when switching from System 2 to System 1 only. It works with no issues most of the time. However, every once it a while, after running hidapitester.exe to switch the keyboard back to System 1, the keyboard will immediately "bounce" back to System 2. This is visible by observing the white "Easy Switch" buttons on the keyboard. I'll see the "1" key solidly illuminate briefly followed by "2" flashing once and then solidly illuminating again. A few successive retries typically yield the same "bouncing" behavior, and then the normal switching behavior will resume and things will be fine again for a while.

That's a bit irritating and I never have this problem with the mouse, or when the keyboard switches to System 2. An easy workaround is just to send many of the same hidapitester.exe commands to switch the keyboard. Unfortunately, an even bigger problem is that the keyboard will eventually get "broken" if the "bouncing" behavior happens over the course of many system switches. The "shift" key will get stuck on System 2 only. This is not visible on the Windows 10 On-Screen Keyboard and the caps-lock key can't be used to fix it. The only fix that I've found is to reboot System 2.

I used Wireshark to try to figure out what is going on during a normal "Logitech Flow" keyboard switch on the Bluetooth-connected System 2, just to see if there is more involved than just sending the above control commands. The only thing I noticed is there there are 3 USB URB_INTERRUPT packets sent to the keyboard right before the system switch control command gets sent. Each one has a Packet Data Length of 0. I'm thinking that these may prep the keyboard for the switch to System 1 by telling it to flush any remaining input (or something like that) but I'm not sure. Also, I don't know how to send those URB_INTERRUPT packets with hidapitester.exe.

Has anyone else experienced this keyboard "bouncing" and "shift-key-stuck" behavior? Have you had any luck with sending URB_INTERRUPT packets to fix it? I thought that maybe the keyboard has trouble switching when it is in use (for Bluetooth only), so I bound the switching script to a mouse button to ensure the keyboard remained idle before and during the switch. However, I still observe the same issues after a while. I also thought that this may be a driver issue on System 2. However, using the keyboard switching buttons never causes the bad behavior and the mouse always switches fine with hidapitester.exe, so I'm hoping that there is a way to fix the problem by sending additional USB flush/quiesce/interrupt commands before/during the keyboard switch to System 1.

If anyone has any ideas, please let me know. Also, thanks for all the work put into this so far and all the detailed posts. I would not have gotten this far without them.

@tsplat
unfortunately, I also face similar issue. I don't know better way than sending switch command multiple times.

@dnlw07 - Thanks for your reply. Have you also run into the "shift-key-stuck" problem?

@tsplat
No, I don't.
Only issue I face is that during the mouse/keyboards switch there is 20% chance that the channel will bounce back.
I can live with that but its annoying.

Hello all,
So a little backstory: I've got Logitech MX Ergo for a few years now, and I recently bought MX Keys with switching hosts in mind, to have a nice setup with 3 monitors, mouse and keyboard which I would be able to switch with one click between my private PC and company issued laptop for work. Oh boy, was I disappointed that this is impossible with stock Logitech software. There is Flow, but I am constantly connected via VPN on my laptop and with that, Flow simply doesn't work. Not to mention that there isn't even an option to launch a batch file upon switch or basically perform any additional action, so switching monitors was never an option.
So I started searching and got here. With quite a bit of inspiration from you guys, I was able to put together a neat little python script that achieves everything I wanted.
Well, almost, because firstly I found out that two of my old monitors are damaged, and don't react to control signals (even hardware buttons), and later that I am only able to use MX Keys easy switch keys, not the MX Ergo switch button on top (explained in my repo). However, I'm still considering this as a win, and I'm totally happy with it. I even find it useful to be able to just switch the mouse for a moment, to switch music on the PC or whatever.
And here it goes, here's my script: https://github.com/KonradFoit/logi-kvm
Feel free to ask questions, use it anyway you want. If you'll find some other cool features of some other Logitech devices, feel free to reach me or even make a pull request.
Cheers!

Great thread! Thanks everyone for posting. I managed to get this working for my setup and wanted to post my findings in case it helps someone else with a similar 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 instead of 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: 1-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 max of 6 devices that can be paired to a unifying reciever.
  • 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: 0-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.

Hope that helps!

@JLeikam if you'll look at readme in me repo, you'll find that what you refer to as "ID" in this message is the number of the CHANGE HOST feature of the device. You can find that easily, e.g. with Solaar by running solaar show and look for CHANGE HOST.

@KonradFoit Nice! That's good to know. In my case, I was switching between windows and mac, so wasn't able to use Solaar.

vp777 commented

Adding to what @JLeikam said, the id for MX Master 3 is: 0x0a

Perhaps I misunderstood how this is supposed to work.

Running hidapitester from RECEIVER_2, I can switch MX Anywhere 3 TO RECEIVER_1 or RECEIVER_3, but I can't switch FROM RECEIVER_1 or RECEIVER_3.

What I'm trying to do, if I have MX Keys and MX Mouse set to RECEIVER_2, once I switch the keyboard using the easy keys, I want to bind a command to some other key to take control of the mouse as well, is that possible?

Also, seems like the values for my MX Anywhere 3 is different from the one posted before, so if anyone needs, it's 0x10,0x02,0x0a,0x1e,0x00,0x00,0x00
0x10,0x02,0x0a,0x1e,0x01,0x00,0x00
0x10,0x02,0x0a,0x1e,0x02,0x00,0x00

Amazing insights here, thank you to all that have contributed.

Question, does this method work when your Logitech device(s) are connected via bluetooth or does it only work when using the a Bolt or Unifying receiver?

...I'm having some problems with the keyboard when switching from System 2 to System 1 only. It works with no issues most of the time. However, every once it a while, after running hidapitester.exe to switch the keyboard back to System 1, the keyboard will immediately "bounce" back to System 2.
...
If anyone has any ideas, please let me know.

I've the same. "busdog" tells me to send the command twice, if I press easy switch. So I send all command double time like:

Switch mouse from 2->1 (one line):
hidapitester --vidpid 046D:C52B --usage 1 --usagePage 0xFF00 --open --length 7 --send-output 0x10,0x02,0x09,0x11,0x00,0x00,0x00 --length 7 --send-output 0x10,0x02,0x09,0x11,0x00,0x00,0x00

Hi, I'm new here and have literally no experience in what You are doing,
Did anybody manage to create a working solution for both Win11 and Linux?
I would love to switch both devices back and forth with only one keystroke on the MX keys.

Hi community.

I created cross platform application for linux macos and windows to change source whenever go to edge of screen. It is creating system tray icon and you can activate or do the settings from there. You can emulate mouse movement for not sleeping even you can sync your clipboard from your local network as well. I hope it helps everyone

https://github.com/meliksah/lcs

happy coding :)

executables are in here: https://github.com/meliksah/lcs/releases/tag/v0.0.2

Q3X8 commented

TIP FOR PEOPLE REPLACING DEVICES

My MX Vertical had a failing button so I replaced it with another one. Getting InputSwitcher working again was quite a pain but I finally figured it out.
Even though I unpaired the old device and everything, it was still getting weird. I finally figured something out in BusDog:
This was for the old mouse
--send-output 0x10,0x01,0x0c,0x1e,0x01,0x00,0x00

I was having a hell of a time figuring stuff out. Big tip: When using BusDog, the only button you care about pushing is the easy switch button(s) I got the info not when I left my device but when I pushed the button to come back to it

Anyways, long story short, for whatever reason I had to change the second byte/chunk whatever from 0x01 to 0x03

and I changed the 4th byte but I'm not 100% sure I had to, but I'm over testing it. Hopefully this saves someone else a couple hours
old --send-output 0x10,0x01,0x0c,0x1e,0x01,0x00,0x00
new --send-output 0x10,0x03,0x0c,0x1a,0x01,0x00,0x00

Someone should be a champ and get the IDs of all the Logitech products. ..maybe they should get paid for doing that. Seems like a perfect task for an employee of Logitech. Not like they have access to any of the devices or anything right? Maybe wrap all this in a nice little program for their paying customers. smh

Massive thanks to everyone involved in this!

Complete newbie in this area, so after struggling a bit with figuring it out, I thought of leaving my setup here in case anyone finds it useful:

PC 1: desktop, Win 10, regular Logi Options+, via Logi Bolt
PC 2: laptop behind VPN + proxy, Win 10, the offline version of Logi Options+ with Flow (which can't connect because of the VPN I'm guessing), via Bluetooth
Peripherals: MX Master 3S + MX Keys S

marcelhoffs has left some very useful directions about Bluetooth connections at the end of his readme at: https://github.com/marcelhoffs/input-switcher . I took the id for the mouse from there and it worked right away via the dongle. However I couldn't find any info about the id of the keyboard (the id for the MX Keys didn't do the trick). Since I don't have a Linux machine, I setup Flow with a third PC and traced it using Wireshark and USBPcap. You can filter by usb.data_fragment to get what's being sent. One of the first entries contained the id for the MX Keys S which for added confusion turned out to be the same as the id for the mouse O.o.

So PC1 to PC2 turned out to be:
rem Switch MX Master 3S, Logi Bolt, slot 2, to channel 1
.\hidapitester.exe --vidpid 046D:C548 --usage 0x0001 --usagePage 0xFF00 --open --length 7 --send-output 0x10,0x01,0x0a,0x1e,0x00,0x00,0x00

rem Switch MX Keys S, Logi Bolt, slot 3, to channel 1
.\hidapitester.exe --vidpid 046D:C548 --usage 0x0001 --usagePage 0xFF00 --open --length 7 --send-output 0x10,0x02,0x0a,0x1a,0x00,0x00,0x00

The first index in the Logi Bolt wasn't in use probably as a result of all the switching, reconnecting and testing. The 4th byte seems to have several valid values so literally the only meaningful difference was the position in the Logi Bolt (the 2nd byte).

The reverse direction was trickier. I followed the same logic however instead of slots there are different Bluetooth pseudo devices. The slot byte seems irrelevant. I used hidapitester.exe --list-detail to get the ids for the Bluetooth devices so the result came out as:

rem Switch MX Master 3S, via Bluetooth, slot N/A, to channel 2
.\hidapitester.exe --vidpid 046D:B034 --usage 0x0202 --usagePage 0xff43 --open --length 11 --send-output 0x11,0x00,0x0a,0x1e,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

rem Switch MX Keys S, via Bluetooth, slot N/A, to channel 2
.\hidapitester.exe --vidpid 046D:B378 --usage 0x0202 --usagePage 0xff43 --open --length 11 --send-output 0x11,0x00,0x0a,0x1a,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

I have same issue with MX ergo mouse and Ergo K860 keyboard

Hey @nefricore, I managed to switch the keyboard (MX Keys S) following your message, but I'm having trouble finding the id for the mouse (I have a MX Anywhere 3S).
Looking at your commands it seems the device id is the third value of the string, but how did you find it?
My keyboard value is 0x0a, I tried every value from 0x00 to 0x1e and still nothing... Is there a way to find out that value?

Hey @davide-stefanini ,
I came across three different methods to get the ID:

  • People use Solaar in a Linux box to get the ID. I haven't tested it myself.
  • Install Logi Options+ with Flow on two Windows PCs on the same network. Then you can trace the communication between them using Wireshark and USBPcap by switching the mouse via Flow. It's a bit tricky if you've never dabbled in Wireshark but you can filter by usb.data_fragment which makes it much more manageable. One of the first entries had the correct ID in my case.
  • I also came across this script to iterate over all hex values: marcelhoffs/input-switcher#15 (comment). I remember that I tried it as well and it works as long as you adjust the other bytes in the loop correctly.

I hope that helps.