WhiteMagic / JoystickGremlin

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

Feature suggestion: set button pressed #278

Closed j987456 closed 4 years ago

j987456 commented 4 years ago

Dear WhiteMagic, it would be great if you add a new function to scripts (plugins) to maintain vJoy button pressed until you decide to release it. Something like: vjoy[1].button(1).set_pressed = True that maintains the button pressed until you set it to False. vjoy[1].button(1).set_pressed = False

Consider to add it, it would be useful in certain situations.

Thank you!

WhiteMagic commented 4 years ago

You can get that functionality by using a Chain container with two Macro actions, one macro sets the desired vJoy button to pressed and the other one releases it. This will then cycle the button between pressed and released with subsequent presses of the physical button.

If you actually want to do this in a plugin then there is nothing preventing you from writing a simple function or class that manages this. There is not really a utility library in Gremlin that is intended for plugins.

j987456 commented 4 years ago

Thank you for the answer. Talking about plugins, can you give an example, please? Because what I managed to do is to set a button pressed using a periodic function with a very small interval, but in this case the button is pressed many times, which in certain situations is different from keeping a button pressed without releasing it.

WhiteMagic commented 4 years ago

I think I might not be getting what you're trying to implement, as setting a button state is a single line as you've written out above. That button will retain this state unless it is changed. That's why I assumed that you wanted something that effectively toggles a button between pressed and released state.

If all you want is to set a button as pressed or released then the two lines you posted above are all that's needed as they won't change state unless told otherwise. If that's not the behaviour you're getting then something else will be overwriting this in your setup. In that case, it might be helpful to post what you have here, as it might be something that's obvious to me but not that obvious in general.

j987456 commented 4 years ago

Yes, you are right, using this: vjoy[1].button(1).is_pressed = True the button remains pressed until you set it to False.

It was a problem of the utility that I use to check the button state, it seemed that the button did not remain pressed but was pressed and released. Using "Monitor vJoy" it is clear that the button remains pressed until it is set to False.

Sorry for opening this thread!

WhiteMagic commented 4 years ago

No worries, no harm in asking questions.