ajchellew / zwiftplay

An attempt at decoding the Zwift Play controllers
22 stars 2 forks source link

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

Open Jouzer opened 7 months ago

Jouzer commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

@ollypsilon hopefully you have had more luck!

ajchellew commented 7 months ago

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

image

Jouzer commented 7 months ago

Cool to see you progress, I’ve been way too busy to get into it. Looking good!

su 10.12.2023 klo 18.25 ajchellew @.***> kirjoitti:

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

image.png (view on web) https://github.com/ajchellew/zwiftplay/assets/17216760/9324b208-303e-4c0f-a69f-726d4dddee24

— Reply to this email directly, view it on GitHub https://github.com/ajchellew/zwiftplay/issues/1#issuecomment-1849011494, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH3ULW37ZLTU3CELJDY7D7LYIXO67AVCNFSM6AAAAABAFSJCXGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBZGAYTCNBZGQ . You are receiving this because you were mentioned.Message ID: @.***>

Jouzer commented 7 months ago

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 commented 7 months ago

@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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 5 months ago

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 commented 1 month ago

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 commented 1 month ago

How do you send the feedback to indievelo?

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno lun 13 mag 2024 alle 21:28 Joshua Taillon < @.***> ha scritto:

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 https://indievelo.com/about/. 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...

— Reply to this email directly, view it on GitHub https://github.com/ajchellew/zwiftplay/issues/1#issuecomment-2108643554, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALYWGHVVWY3V66H4L4XXTZCEH6HAVCNFSM6AAAAABAFSJCXGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBYGY2DGNJVGQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jat255 commented 1 month ago

@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 commented 1 month ago

Hah Ok thanks

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno lun 13 mag 2024 alle 21:56 Joshua Taillon < @.***> ha scritto:

@cagnulein https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/ajchellew/zwiftplay/issues/1#issuecomment-2108686964, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALYWHLMKZATNHCKP2EHRLZCELHFAVCNFSM6AAAAABAFSJCXGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBYGY4DMOJWGQ . You are receiving this because you were mentioned.Message ID: @.***>