MarkJerde / Logitech-G13-Profiles

My Logitech G13 Profiles
4 stars 0 forks source link

Support for joystick? #1

Open RaulRG opened 2 years ago

RaulRG commented 2 years ago

thank you VERY much for the great Extra Keys. I love my G13 and I just switched to a MacBook and was missing it. Will you add support for the joystick? It is the only one feature I am really missing. Would you need any help to implement it? I am quite experienced programming with C++ and C#, but I never did any programming under MacOS. Again, great work with Extra Keys!!

RaulRG commented 2 years ago

Anyone monitoring this repository?

MarkJerde commented 2 years ago

Hi Raul. Yeah, I get emails when issues are created, but it is busy season. Glad you like it. Joystick support is one of many things in the back of my mind, though support for editing profiles is a more immediate priority. I've never used the G13 as a joystick (even the Logitech software mapped the stick to five additional macro numbers, without any conventional joystick concept, in conventional profiles and I never looked into making it work as a joystick). If you can elaborate on how you have used the G13 as a joystick (and even share any profile files you have used with that) it would help me understand what joystick support should do.

Thanks, Mark

RaulRG commented 2 years ago

Hello Mark,

sorry, I didn't want to sound rude. I really appreciate what you have done with Extra Keys.

i just switched from my PC to a MacBook Pro and there is only one game I play: World of Warcraft (shame). Everything is working with Extra Keys, but the "buttons" from the joystick don't. I mapped the buttons G26, G28, G29 and G27 to W, S, Q and E respectively. When I move the joystick I see the buttons and their mapped keys (macro) in Extra Keys, but the game does not receive them. Sometimes you see that there is a small movement, so it seems that somehow they go through. I think if this worked the next problem would be than the keys should repeat when you keep the joystick in a position. For example if you keep the joystick up it should send "W" in a loop. Below is my profile. I uploaded as txt file instead of xml because of Github.

Wow_G13_2.txt

I am sorry for taking your time.

Kind regards, Raul

MarkJerde commented 2 years ago

Hi Raul, No offense taken. I’ll take a look at your profile when I have a chance. The way you use the joystick should work just fine (assuming I’ve released an update since I put the repeat code in), but the profile will make it easy for me to check and fix anything. Thanks, Mark

RaulRG commented 2 years ago

Hello Mark, I did some more tests. I used the same profile, but using Visual Studio Code as application. I can see the movement keys coming (W, S, Q, E). This means the mapping seems to be correct.

As any other keys are working perfectly under World of Warcraft, i suppose somehow the way the keys are sent to the application in the case of a joystick are being ignored by the game.

Thank you for taking a look at this. Raul

MarkJerde commented 2 years ago

Hi Raul, It's interesting that you see Extra Keys recognizing the inputs and the game not responding, but even more interesting that it sounds like it responds a small amount. I wonder if Extra Keys is just synthesizing they keystroke down and up so quickly that the game views it is a very tiny input. Putting a repeat on the macros might be all you need then. The current version of Extra Keys on the App Store does support repeat. Here's an example from one of the profiles in this repository:

<macro original="true" repeatdelay="25" guid="{07A21148-968F-4E0E-917B-D21F1336BBEE}" hidden="false" name="Nav Back" repeatmode="pressed">

If you add the repeatdelay="25" and repeatmode="pressed" parts to your W, S, Q, and E macros and then reload the profile in Extra Keys you should be able to see it repeating while the key is held. Changing pressed to toggle would make the macro keep repeating from one tap of the key / joystick until the next tap of that same key / joystick-direction, which probably isn't what you want but might help for other controls in the game. The repeatdelay is in milliseconds, so you can try out values to find which gives you the degree of responsiveness you'd like, with smaller being more responsive (possibly up to a point) I'd guess. 25 will send the key down and up 40 times per second.

It's possible that the speed of the key down and up still conflicts with the game's assumption that inputs are from a human tapping keys and expecting some minimum time between down and up. Assuming the game has its own key-repeat handling for a held key, the repeating of a key by Extra Keys may not deliver quite the same effect. Let me know how it works out and I'll see about some other tweaks to the app that I have in mind if needed.

Thanks, Mark

RaulRG commented 2 years ago

Happy New Year, Mark! Thank you very much. I will try it and give you feedback.

RaulRG commented 2 years ago

Hello Mark, I just tried and it seems we are going in the right direction. If I understand it right, this will cause sending the keys in a loop every 25 ms. This seems to be the behaviour in the software right now. I just press the joystick forwards and it looks as if I press the key "W" multiple times. The movement is very strange and it even caused a disconnection from the game (it seems they cannot cope with the "click" speed). This is different with the behaviour under Windows. There pressing the joystick forwards behaves as if i just keep pressing the "W" key. This means something like a keydown "event" without the keyup.

Pressing the key "W" and keeping it pressed makes the character run in the direction (good!), but moving the joystick to the corresponding direction makes the character do little "steps".

Kind regards, Raul

RaulRG commented 2 years ago

Hello again Mark,

I think this is the problem: when you press the joytick forwards it probably should just send a keydown, but not the corresponding keyup till the joystick moves away from the forwards position.

I tried this:

  <macro original="true" guid="{DB0A670A-0F4D-4684-913F-39E71D91635F}" hidden="false" name="Backwards">
    <multikey xmlns="http://www.logitech.com/Cassandra/2010.1/Macros/MultiKey">
      <key direction="up" value="W"/>        
      <key direction="down" value="S"/>
    </multikey>
  </macro>

  <macro original="true" guid="{86A22338-0069-43FB-B48B-5CBB7B18B46A}" hidden="false" name="Forwards">
    <multikey xmlns="http://www.logitech.com/Cassandra/2010.1/Macros/MultiKey">
      <key direction="up" value="S"/>
      <key direction="down" value="W"/>
    </multikey>
  </macro>

It was just to see the behaviour and when I press forwards it keeps moving forwards forever (due to the key down W but not the keyup). I did the same with backwards and now i can keep changing the direction forwards and backwards using the trick that when I press forwards I do a keyup for the key used for backwards and the other way around.

At least I can see that WoW reacts as intended, It is just that the support for the joystick probably sends now the key down and key up events. As it seems, the Windows' software from Logitech was just sending keydown and then key up for the key when the direction changes. Does it make any sense?

Update: if I map some other keys like G5, G6, G7 and G13 to the left, forwards, right and backwards macro it behaves exactly like the joystick. I will test the behaviour under Windows using the exact same map.

Kind regards, Raul

RaulRG commented 2 years ago

Hello again Mark,

just tested under Windows using Logitech Gaming Software.

There is a difference there. If I press a key (lets say G6) that is mapped to the Forwards macro (key W) and keep it pressed then the toon under WoW keeps moving forwards till I release the key. This means that the normal keys and the joystick behave identically. You can keep them pressed and you probably get the key down event, but not the key up.

Under MacOS with Extra Keys it seems than pressing a key sends a keydown and a keyup event even when I keep the key pressed.

Under Windows there is another nice feature: if you press both keys for forwards and left and keep them pressed the toon runs diagonally forwards and to the left. The same is true if you move the joystick in the North/East direction.

I hope I could explain it right.

Kind regards, Raul

RaulRG commented 2 years ago

Hello Mark, I just implemented an application with Objective C that is reading both the keys and the joystick from my G13. It seems to be working as World of Warcraft expects them (and as the Logitech Gaming Software does under Windows). Of course, in my case it is easier as I am just interested on sending keys.

Currently I am just displaying the events to see if the logic is right. When I press or release a key I get the information about the key and if it is a keydown or keyup event. For example, if I press the G6 key I get the keydown and when I release the key the corresponding keyup.

I did the same with the joystick using the x and y position and mapping it to a virtual up, left, right and down keys. When I move the joystick to the left I "send" the event for the left keydown and when i move the joystick away from the left side the corresponding keyup event. The log seems to be exactly what it should be.

As I am not a MacOS programmer I don't know now how to check the software sending the keys to the external application. I've found the CGEventPostToPSN method, but I don't know how to get programmatically the PSN for an external application.

Could you please give me some advice? I can provide you my software when it is ready if you are interested.

Thanks! Raul

RaulRG commented 2 years ago

Hello Mark,

sorry for spaming you :-(

I just got it working!! I use NSWorkspace.sharedWorkspace.frontmostApplication.processIdentifier to get the pid for World of Warcraft when it is the front most application and then post the event with CGEventPostToPid.

It is working perfectly!!! The joystick behaves as should. I don't know if there is a better way as now I am doing it every time I post an event. Probably there must be a way of getting notified when the front most application changes.

Kind regards, Raul

MarkJerde commented 2 years ago

Hi @RaulRG, Extra Keys 1.1.1 was released this week, which should resolve the held-key handling issue you had. Please let me know if you have any further issues. Thank you, Mark

RaulRG commented 2 years ago

Hello @MarkJerde ,

thank you very much!

Maybe I will give it a try. As I said, I implemented a solution myself and is working great. I cannot configure it using a XML, but for my needs it does exactly what I needed.

Hope the feature is useful for any other Extra Keys user, as it makes the joystick (and any other key) behave as probably expected.

Best regards, Raul

fitur commented 2 years ago

Hello @MarkJerde ,

thank you very much!

Maybe I will give it a try. As I said, I implemented a solution myself and is working great. I cannot configure it using a XML, but for my needs it does exactly what I needed.

Hope the feature is useful for any other Extra Keys user, as it makes the joystick (and any other key) behave as probably expected.

Best regards, Raul

Hi, Mind sharing your solution? Thanks and have a nice weekend!