WhiteMagic / JoystickGremlin

A tool for configuring and managing joystick devices.
http://whitemagic.github.io/JoystickGremlin/
GNU General Public License v3.0
313 stars 46 forks source link

Press key when entering an axis range and press another when leaving it again #384

Open Houndmux opened 2 years ago

Houndmux commented 2 years ago

I want an axis to press a key when entering a specific range and pressing another when leaving it again. I did this with two macros, one to press and relase the key with "activate when axis is between 0.5 and 1.0 when entering the range from below" and one macro to press the other key when between 0.0 and 0.5 and entering from above.

In principle this works, however when moving the axis back and forth quick, it sometimes skips the "inbound" or "outbound" event, thus not pressing the key. I tried including short pauses before, between or after the press/release actions and tried macro settings both with "Exclusive" enabled or disabled. I also tried overlapping the ranges or leaving a gap (i.e. activate in 0.4:1.0 and deactivate in 0:0.6 or activate in 0.6:1.0 and deactivate in 0:0.4), but it did not help. I also tried the map to keyboard function, same problem.

Maybe this is a problem with poll frequency, I don't know. Is there an alternative way to get the desired behaviour?

WhiteMagic commented 2 years ago

I suspect this isn't so much the actions not triggering, as there is actually code to ensure this doesn't happen, but rather the actions being executed in an "incorrect" order. I suspect if you actually move axes fast enough to cause this issue regularly the only robust solution is a custom plugin where it is possible to detect this and then handle it correctly.

Houndmux commented 2 years ago

Thanks. With incorrect order you mean the macros themselves or the execution of the pressed/released action within the macros? Say I assign "E" for entering the range and "L" for leaving, then the sequence should be ELELEL... but I get sequences like ELEEL... or ELLEL.... If the key presses were just executed in the wrong order, it would look something like ELEELL...

I also tried additionally assigning a virtual button as a flag to make sure the enter or leave action cannot be executed in immediate succession: the virtual button gets pressed when the range is entered and released when it is left. Condition is that "E" can only be executed when the virtual button is released and "L" only when the virtual button is pressed. This did not work either.

WhiteMagic commented 2 years ago

The sequence of the different macros is what is likely not happening in the expected sequence. The actions inside the macro are guaranteed to be executed in order. The reason is that when you move an axis fast and depending on its resolution and the device's update rate you will "jump" over a large range of values. Gremlin detects this and emits the "missed" events. However, there is nothing ensuring those "missed" events are emitted or executed in the order in which they'd occur if the axis got moved slower.