Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Device support switching between computers (feature CHANGE_HOST) #806

Closed
mkkot opened this issue Jun 7, 2020 · 30 comments · Fixed by #844
Closed

Multi-Device support switching between computers (feature CHANGE_HOST) #806

mkkot opened this issue Jun 7, 2020 · 30 comments · Fixed by #844

Comments

@mkkot
Copy link

mkkot commented Jun 7, 2020

More like a question: is it possible to change device controlled by logitech mouse or keyboard (keys 1, 2, 3) programmatically?

Solar shows HID++ feature:
9: CHANGE HOST {1814}
But I don't know how to use it or if it's what I'm looking for.

Why?

I have a laptop and normal PC and I switch between them often. I have already prepared input source switch for monitor and now I would like to automate switching mouse and keyboard.

@pfps
Copy link
Collaborator

pfps commented Jun 7, 2020

This should be possible, and someone was trying to get it to work, but I can't find the issue right now. The problem is that Solaar tries to remember the last value for settings, so that if you use this setting to switch to the other host then Solaar will keep on restoring the setting, which will switch to the other host.

@FFY00
Copy link
Member

FFY00 commented Jun 7, 2020

This should be possible but what kind of interface are you expecting?

@mkkot
Copy link
Author

mkkot commented Jun 8, 2020

@pfps by "this setting" you mean 9: CHANGE HOST {1814}? Is this correct place to look? To be honest I don't know how to play with this setting using cli, tried but couldn't change it.

@FFY00 I guess that anything goes. I'm not a great fan of C but python and bash are fine.

@pfps
Copy link
Collaborator

pfps commented Jun 8, 2020

I don't have a device that has this feature, but I believe that 1814 is the feature to work with. I don't have documentation on the feature but I do remember that someone was trying to implement a change host functionality.

@mkkot
Copy link
Author

mkkot commented Jun 8, 2020

Could someone please point me to some documentation on how to start working on this 1814 feature? I have never had any experience with HID interface and I have no idea how to start. You guys probably can name at least few tools and give some examples on how to start hacking on this.

My understanding is that solaar can list this feature but doesn't support any operations on it.

@pfps
Copy link
Collaborator

pfps commented Jun 8, 2020

Getting documentation is a hit or miss effort. You could open an issue at https://github.com/Logitech/cpg-docs

@FFY00
Copy link
Member

FFY00 commented Jun 9, 2020

@mkkot Solaar doesn't provide any API, the most we can do is add a CLI command.

@mkkot
Copy link
Author

mkkot commented Jun 13, 2020

@FFY00 If you have time and will to implement it, then CLI is fine with me. I would happily use it in my bash script.

If I can help in any way, just tell me what's needed. I was actually browsing the repo myself today but it's a lot to take. For starters I would like to know which files I need to open in IDLE and which function I can use and how to send some values to a certain registry.

@pfps pfps mentioned this issue Jun 13, 2020
99 tasks
@barolo
Copy link

barolo commented Jun 17, 2020

@mkkot Woudn't that https://github.com/debauchee/barrier serve your use case?

@mkkot
Copy link
Author

mkkot commented Jun 17, 2020

It's an interesting project, but I don't think it works in the way I want. Especially, I don't want to have both OS-es opened at 2 different monitors at the same time. Also, it generates some overhead, I guess that barrier must be installed on both systems and communicate with each other. I would prefer to have simple solution instead. But thanks for the suggestion anyway :)

@barolo
Copy link

barolo commented Jun 17, 2020

Understandable, wouldn't your idea only work with Linuxes though? AFAIK neither under Windows nor macOS is it possible to switch it programmatically. It's one of the most common request on Logitech's forums too.

@mkkot
Copy link
Author

mkkot commented Jun 17, 2020

Yes, that's true. Since I can't really rely on what kind of secondary system/laptop is connected to my monitor, I decided that I will control switching from my primary PC (which runs Linux).

It's true that for switching from secondary system back to my primary PC requires switching keyboard manually first to my primary PC. But since I need to press keys on it to trigger my script anyway, then I decided it's not such a big deal. The script would switch mouse (which normally requires 2 presses) and monitor (at least 3 presses on very uncomfortable buttons).

@barolo
Copy link

barolo commented Jun 17, 2020

The usefulness of that is quite limited, I can see another use case of implementing "change host" though, switching keyboard and mouse together.
I'll play around with packet sniffer, to see what it spits during switching.

@mkkot
Copy link
Author

mkkot commented Jun 17, 2020

Actually it's up to the user to decide what he/she needs and up to the system to have the feature :) For me it's useful, for you maybe not, but that's fine. Also, switching mouse and keyboard at the same time is so obvious that you would expect it to work this way by default.
What sniffer are you using?

@barolo
Copy link

barolo commented Jun 17, 2020

Actually it's up to the user to decide what he/she needs and up to the system to have the feature :) For me it's useful, for you maybe not, but that's fine. Also, switching mouse and keyboard at the same time is so obvious that you would expect it to work this way by default.
What sniffer are you using?

You can use WireShark for USB packet sniffing.
I didn't mean it personally but in general, that it limits its usefulness to Linux only environments, with mixed OSes, it's not that much less tedious

@barolo
Copy link

barolo commented Jun 18, 2020

Sniffed a bit, unsurprisingly, keyboard doesn't send anything to the host on switch, it's internal, only when coming back it sends some info, I'm guessing with the host/button associations since L_Options have them on display.
Guess someone would have to sniff out the Flow functionality to get the command from the host, which is what he #582 (comment) did apparently.
I don't have two machines with working Flow atm unfortunately.

@pfps
Copy link
Collaborator

pfps commented Jun 20, 2020

@saue0 Can you comment here on what you did for switching?

@barolo
Copy link

barolo commented Jun 20, 2020

This is what gets sent on host switch when screen edge is touched. Left edge, from host 3 to 2.
Switching forth and back.

flow.zip [ just mouse ]
and here is mouse linked with keyboard switching together flow_mouse_w_keyboard.zip

It starts around first HID++ packet, rest is just mouse movement.
It's actually Flowing between two Windows VMs, which wild and weird ;)

@pfps pfps changed the title Multi-Device support switching between devices Multi-Device support switching between computers (feature CHANGE HOST?) Jun 28, 2020
@pfps
Copy link
Collaborator

pfps commented Jul 9, 2020

@saue0 There is documentation for this feature in https://drive.google.com/drive/folders/0BxbRzx7vEV7eWmgwazJ3NUFfQ28
Look for 0x1814_....

@pfps
Copy link
Collaborator

pfps commented Jul 9, 2020

@saue0 I'll try to see what it would take to add a timeout when looking for a reply.

@pfps
Copy link
Collaborator

pfps commented Jul 9, 2020

@saue0 The code that waits for a reply is lib/logitech_receiver/base.py function request. The information there is contradictory. There is a comment that the function waits indefinitely, but the read has a timeout. I guess that the way to see what is really going on is to add debugging statements inside the loop. Can you do that? (If not, I can create a PR with some extra debugging code.)
Edit: It does appear that this code does not wait indefinitely but does time out. If you experience something different please try to find out what is going on.

@pfps
Copy link
Collaborator

pfps commented Jul 9, 2020

@saeu0 I see that you used range for the setting. I think choices might be better (even though it is a range of sorts).

@barolo
Copy link

barolo commented Jul 9, 2020

@pfps Seeing both I'd prefer yours. Truth be told, personally I don't care as I'm going to use only command line part of it. I have two Linux machines which I've set to switch when touching right top corner on one and left-top on another, it's great.
Amazingly it surpasses what Logitech Options allow you to do.

@saue0
Copy link

saue0 commented Jul 9, 2020

I'm using only the command line as well. So it does'nt mather. @pfps will you add "change_host" in your release ?

@pfps
Copy link
Collaborator

pfps commented Jul 9, 2020

@saue0 I'm not quite sure what you are asking for. If you think that your code is ready the thing to do is to put in a PR for it. However, that's going to require some work on your part as FFY00 just recently added code style checks, with the result that no old changes will rebase sucessfully. So you'll have to download the current version of Solaar and do some editing.

@pfps
Copy link
Collaborator

pfps commented Jul 9, 2020

I've taken the code by @saue0 (thanks for the ideas, particularly turning off persisters) and put together a setting for change host. It's not quite ready for testing yet because it depends on the changes for MULTIPLATFORM and this hasn't been completely debugged yet.

@pfps pfps mentioned this issue Jul 10, 2020
@pfps pfps changed the title Multi-Device support switching between computers (feature CHANGE HOST?) Multi-Device support switching between computers (feature CHANGE_HOST) Jul 11, 2020
@pfps pfps closed this as completed in #844 Jul 12, 2020
@pimvullers
Copy link

pimvullers commented Jan 10, 2022

Just discovered this package and it indeed works great for switching both keyboard and mouse using the keyboard from the Linux host running solaar to my other system (thanks a lot for this feature). rules.yaml:

%YAML 1.3
---
- Rule:
  - Key: [Host Switch Channel 1, pressed]
  - Execute: [solaar, config, MX Master 3, change-host, '1']
  - Execute: [solaar, config, MX Keys, change-host, '1']
- Rule:
  - Key: [Host Switch Channel 2, pressed]
  - Execute: [solaar, config, MX Master 3, change-host, '2']
  - Execute: [solaar, config, MX Keys, change-host, '2']
- Rule:
  - Key: [Host Switch Channel 3, pressed]
  - Execute: [solaar, config, MX Master 3, change-host, '3']
  - Execute: [solaar, config, MX Keys, change-host, '3']
...

Unfortunately that other system is running Windows (company laptop, so running something like barrier won't work since it's network activity is restricted by VPN).
I assume there are no options to force enable a (wireless) link with a previously connected device? Because after the host switch the tool reports: no online device found matching 'mx master 3'

Alternatively, since Solaar is python code, it should potentially run on Windows. I expect the main issue would be the interaction with the device. Would it work if the receiver driver would be switch to a libusb version using something like https://zadig.akeo.ie/
Any clues/guidance on how to get started here?


Edit:
Found Logitech/logi_craft_sdk#28 which at least covers the sending commands part. Now I need to go through Solaar codebase to figure out how the diverting of keys is handled, such that I can use them as triggers for the switching script.

@pfps
Copy link
Collaborator

pfps commented Jan 10, 2022

The main part of Solaar depends on two aspects of Linux:
1/ udev - to find Logitech devices and to be notified when new Logitech devices show up
2/ /dev/hidraw* - to read and write the raw messages that the devices use
Porting Solaar to Windows (or MacOS) needs equivalent functionality there.

Diverting of keys is done via the Reprogrammable Keys feature of the Logitech HID++ protocol. There is documentation of this feature in the Logitech Google Drive repository at https://drive.google.com/drive/folders/0BxbRzx7vEV7eWmgwazJ3NUFfQ28?resourcekey=0-dQ-Lx1FORQl0KAdOHQaE1A
The main document is
https://docs.google.com/document/d/1Nj-AKFPRdmuz6s4GcXgC2A3pRo2kICe6VDsK6KKI7q0
but you will also likely need the HID++ 2.0 document at
https://docs.google.com/document/d/1GHdN422ikwGmCepKJW9hbLUu9VKRQszrzASRjgzvZJo

(Edited to include the correct URLs for the documents.)

@pimvullers
Copy link

pimvullers commented Jan 11, 2022

Thanks a lot for the support. In the end I decided to undo the reprogramming, to still use those keys to switch the keyboard independently and instead use the gesture button of the mouse to trigger the switch. In particular since I could also remap this button using Logitech Options to trigger a script that uses hidapitester binary to send the change-host commands.

For others interested; rules.yaml:

%YAML 1.3
---
- Rule:
  - MouseGesture: []
  - Execute: [solaar, config, MX Master 3, change-host, '1']
  - Execute: [solaar, config, MX Keys, change-host, '1']
...

Switch script (Using https://github.com/todbot/hidapitester):

@echo off

rem Switch keyboard 
.\hidapitester.exe --vidpid 046D:C52B --usage 0x0001 --usagePage 0xFF00 --open --length 7 --send-output 0x10,0x01,0x09,0x11,0x01,0x00,0x00

rem Switch mouse
.\hidapitester.exe --vidpid 046D:C52B --usage 0x0002 --usagePage 0xFF00 --open --length 20 --send-output 0x11,0x02,0x0A,0x18,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

@pfps
Copy link
Collaborator

pfps commented Jan 11, 2022

For anyone who wants to also use this method of switching on Windows, be warned that the exact commands depend on the device model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants