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

How much more work would it be to translate to keyboard presses? (in WIndows environment) #1

Open
Jouzer opened this issue Dec 4, 2023 · 16 comments

Comments

@Jouzer
Copy link

Jouzer commented Dec 4, 2023

Hey, I'm looking at possibly coding myself a program that would pick up from here and translate Zwift Play buttons to keyboard presses. I'm not familiar with coding drivers, so I was hoping it could just be a program, maybe leveraging https://github.com/Snoothy/UCR or similar if necessary

That way you could control almost anything in a Windows interface, control music player, play indieVelo or many other games, etc.

However since I'm not familiar with this coding language and modern I/O stuff is something I'll have to learn, I imagine this same idea has popped your head. How much more work on this would it be to achieve it, do you have any idea? Do you already happen to know is there going to be some hard wall or a tedious long struggle? I've come to notice in late projects that in some cases Windows 10 has implemented difficult hurdles in security sensitive areas, which HID emulating might fall into

@Jouzer Jouzer changed the title How much more work would it be to translate to keyboard presses? How much more work would it be to translate to keyboard presses? (in WIndows environment) Dec 4, 2023
@Jouzer
Copy link
Author

Jouzer commented Dec 4, 2023

Sorry just realized this is Android based, so probably will need a big redo, but still I kept this question in case you are familiar with Windows programming.

@ajchellew
Copy link
Owner

Hi @Jouzer

I do happen to have been a Windows desktop C# developer slightly longer than I've been an Android one.

I've never directly made a HID and think there are probably challenges to that.

The encryption libraries should be standard and accessible to a .NET application.
The other challenge is probably using Bluetooth Low Energy with Windows as when I've previously looked support has been near non-existent, but might be different if targeting just Windows 10/11.

I've spent a lot more time failing to emulate a Zwift Play device, so will probably have a look when I have a spare day...

@ollypsilon
Copy link

I'm currently doing my first steps with the controllers on Windows. Maybe I'll post an update once I'm confident it's worth to share.

@ajchellew
Copy link
Owner

I've just added my initial effort to get this working in windows.

  • BLE connection sorted thanks to https://github.com/inthehand/32feet
  • Encryption libraries appear to be available but currently decryption doesn't work needs more debugging to figure it out.
  • Looked into HID, would be much easier for the C# code to virtually press keys than to write a HID driver.

@ollypsilon hopefully you have had more luck!

@ajchellew
Copy link
Owner

Cracked it, switching to BouncyCastle for the key exchange made things a whole lot easier.

image

@Jouzer
Copy link
Author

Jouzer commented Dec 11, 2023 via email

@Jouzer
Copy link
Author

Jouzer commented Dec 12, 2023

I looked through the code and it's beautiful simple, my code would not be so concise :D

edit; I earlier had a link to a StackExchange where there was advice for using windows.forms sendkey but I already realized it's probably not good, https://github.com/michaelnoonan/inputsimulator utilizes it and it states that it's limited to WPF, Forms, console so not a very good one

I work with a lot of languages but never with C#, I'll try to find time to set up the environment and test this, try some things out, thanks alot for the effort!

@ajchellew
Copy link
Owner

@Jouzer just committed a change that seems to work with sending key presses to whatever is in focus. It looks like using this method that it only sends normal keys once, so might need to send loops. but control keys do down/up as expected.

@Jouzer
Copy link
Author

Jouzer commented Dec 12, 2023

I got it running, works like a charm. Thanks again!

I might try to do the UCR plugin for kicks and learning, whenever I find time. I exchanged a word with the dev and he said it'd be a good fit. Unless of course you think it's not something you want to be done with your work

You probably already figured it out but UNKNOWN_NAME somethingValue is actually when you crush the paddle instead of tilting it, pretty neat feature but dunno why it's so poorly documented, it took me days to figure out it even existed

@ajchellew
Copy link
Owner

You probably already figured it out but UNKNOWN_NAME somethingValue is actually when you crush the paddle instead of tilting it, pretty neat feature but dunno why it's so poorly documented, it took me days to figure out it even existed

I had no idea! Its good they've packed in buttons that they aren't using though, shows they've thought about future expansion over immediately selling the new version.

@ollypsilon
Copy link

I've just added my initial effort to get this working in windows.

  • BLE connection sorted thanks to https://github.com/inthehand/32feet
  • Encryption libraries appear to be available but currently decryption doesn't work needs more debugging to figure it out.
  • Looked into HID, would be much easier for the C# code to virtually press keys than to write a HID driver.

@ollypsilon hopefully you have had more luck!

Hi @ajchellew , I'm sorry, I didn't do anything yet as I'm on vacation 😄

@sheitmaster
Copy link

I just want to add some motivation:
Wahoo just added support for virtual shifting to the core and this would surely benefit a LOT of people.

@jat255
Copy link

jat255 commented May 13, 2024

Just chiming in here that I implemented a basic version of something similar for a Zwift Click using Python here: https://github.com/jat255/zwift_click_handling

I'm using it to control the "virtual shifting" feature in indieVelo. I couldn't get the encryption piece working, so it's using the un-encrypted method, but I don't think that's too much of a danger...

@cagnulein
Copy link

cagnulein commented May 13, 2024 via email

@jat255
Copy link

jat255 commented May 13, 2024

@cagnulein I'm using the https://github.com/boppreh/keyboard library to simulate presses of the - and + keys on the keyboard, which indieVelo already uses as shortcuts to control their virtual gearing.

@cagnulein
Copy link

cagnulein commented May 13, 2024 via email

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

No branches or pull requests

6 participants