logi_craft_sdk
logi_craft_sdk copied to clipboard
Device change button does not affect other connected devices
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 40unfortunately while I am trying to send the command using USB-HID-Tool:
usbhidtool 0x046D 0xC52B 0x10 0x02 0x41 0x04 0x71 0x61 0x40I receive following errors:
ERROR: device not connectedand on my second laptop:
ERROR: incorrect response from the deviceCould 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.exefiles downloaded from Github repository?
Have the same issue, on both mac and windows. Would be nice to know how to make it work. Thx!
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:
- Connected first transmitter to Linux machine
- Obtained commands for switching from first device to second
- 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: https://github.com/pwr-Solaar/Solaar/issues/1154#issuecomment-822544534):
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!
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.
- 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 - Then downloaded prebuild library for
hidapifrom: https://github.com/libusb/hidapi/releases/download/hidapi-0.10.1/hidapi-win.zip and prebuild package forhidapitesterfrom: https://github.com/todbot/hidapitester/releases/download/0.2/hidapitester-windows-x86_64.zip - 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.
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