Need help with a Lean script (binding TrackIR axis to keys)

Official forum for open source FreePIE discussion and development.
Post Reply
CapoFantasma97
One Eyed Hopeful
Posts: 2
Joined: Sat Nov 10, 2018 3:52 pm

Need help with a Lean script (binding TrackIR axis to keys)

Post by CapoFantasma97 »

Hello there,
In my quest to bind the tilting of my head to leaning in games, I stumbled upon GlovePie, which did the job but a massive delay. Then I found FreePie, this amazing software that is unfortunately not very intuitive for me that barely knows anything about python.

I found this script here which allows to bind an axis of TrackIR and its value to a key. The problem is, it outputs the key only once and that's it. I need a way to keep the key pressed down as long as the axis value is greater than the chosen threshold, and release the key when the axis value is lower than it.
For example, setting a roll axis value greater than 20 for Q, and when my head is tilted 20 or more degrees it outputs Q, while if it's tilted 19 degrees or less it releases Q and outputs nothing. Same for the opposite (-20 for E, lower than -20 it outputs E, higher than -20 like -19 or more it releases E and outputs nothing).

I have no idea what and how to mess with the script above to make this happen, so any help would be extremely appreciated. :)
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: Need help with a Lean script (binding TrackIR axis to ke

Post by Jabberwock »

The easiest way to do that would be to have the given key pressed when the axis exceeds the given value and released when it is not. For example:

Code: Select all

keyboard.setKey(Key.Q, trackIR.roll > 20)

keyboard.setKey(Key.E, trackIR.roll < -20)
Note that it is not exactly what you have asked for, as it always outputs something - i.e. key is always pressed or released. This might matter if you want to access the same keys in other ways, but I think in your case it does not make any difference.
CapoFantasma97
One Eyed Hopeful
Posts: 2
Joined: Sat Nov 10, 2018 3:52 pm

Re: Need help with a Lean script (binding TrackIR axis to ke

Post by CapoFantasma97 »

Jabberwock wrote:The easiest way to do that would be to have the given key pressed when the axis exceeds the given value and released when it is not. For example:

Code: Select all

keyboard.setKey(Key.Q, trackIR.roll > 20)

keyboard.setKey(Key.E, trackIR.roll < -20)
Note that it is not exactly what you have asked for, as it always outputs something - i.e. key is always pressed or released. This might matter if you want to access the same keys in other ways, but I think in your case it does not make any difference.
Weirdly enough, it works as it's inverted (very easy to fix anyway) and only ingame works as intended (my first test with notepad was tricking me into thinking it only output once as well instead of holding).

But aside from that, it works great. Thanks a lot.
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: Need help with a Lean script (binding TrackIR axis to ke

Post by Jabberwock »

Well, I did not check which way the TrackIR rolls... And if you lean and hold, then technically the key IS only pressed once (and held). Desktop apps are not a good way to test, as key autorepeat is not always handled the same way. For more complex scripts I usually test with vJoy virtual buttons (which light up nicely in Windows configuration) and then rewrite for keys.

Glad I could help!
Post Reply

Return to “FreePIE”