Open metrailer opened 4 years ago
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:
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!
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:
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:
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x04,0x09,0x11,0x01,0x00,0x00
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x11,0x01,0x00,0x00
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x02,0x09,0x11,0x00,0x00,0x00"
./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:
What I should have been doing (and what worked):
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.
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x01,0x0a,0x1a,0x01
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x11,0x01,0x00,0x00
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x04,0x09,0x11,0x01,0x00,0x00
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x01,0x0a,0x1a,0x02
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x09,0x11,0x02,0x00,0x00
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x0a,0x1a
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x01,0x09,0x11,0x00,0x00,0x00"
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output "0x10,0x02,0x09,0x11,0x00,0x00,0x00"
./hidapitester --vidpid 046D:C52B --open --length 7 --send-output 0x10,0x03,0x0a,0x1a,0x02
~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.
BusDog
: http://daniel.net.nz/d/busdog_0.2.2/busdog_x64.exe and used it to sniff hex codes using Logitech Flow fucntionalityhidapi
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.zipcd %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
Very helpful. Thank you!
On Fri, May 14, 2021 at 2:43 PM Twau @.***> wrote:
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 Keys" change-host should give you all possible values/hosts For example I can change with: solaar config "MX Keys" change-host 2 or solaar config "MX Keys" change-host higher
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Logitech/logi_craft_sdk/issues/28#issuecomment-841493846, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADNWLSGR7JF5M377TTN2A3TNWDPXANCNFSM4I5HZXJA .
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
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
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
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.
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 :
I put another Logitech Receiver into second computer and and I got rid of the error:
.. 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 ?
Alexandrescu,
From my experience, you can only send control signals to the dongle on the currently-connected PC.
Here’s the best I can do to explain:
Assume you have a single mouse and 2 PCs - “PC1” and “PC2”
To start, the mouse is currently connected to PC1,
You can run a command on PC1 and tell the mouse to switch to PC2.
Once this is done, you can’t run a command on PC1, asking the mouse to switch back, as PC1 is not in control any more.
Therefore you have to run a command on PC2 and tell the mouse to switch back to PC1
Hope this helps, Andy
On Mon, 1 Nov 2021 at 16:15, Adrian Alexandrescu @.***> wrote:
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: image] https://user-images.githubusercontent.com/51136509/139704151-38bc1415-415e-401d-819e-ff32fa6c7f1f.png I put another Logitech Receiver into second computer and and I got rid of the error: [image: image] https://user-images.githubusercontent.com/51136509/139704213-82044d33-9d19-4d88-9127-ae433c1b4cc1.png .. 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 ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Logitech/logi_craft_sdk/issues/28#issuecomment-956373600, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB5IDLQ6EJF3HYWHYCLMFZLUJ24LNANCNFSM4I5HZXJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
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
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 :)
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.