Jump to content
igge-uc

FreePIE TrackIR script to bind axis values to keys (e.g. bind head roll to leaning in games)

Recommended Posts

Hi everyone,

 

first of all: sorry if I opened this topic in the wrong forum, didn't know where to put it. Mods please move accordingly – thanks!

 

I was looking for a solution to use the roll axis of my TrackIR for leaning in Squad. After searching a bit on the internet I stumbled upon FreePIE, which is a free alternative to GlovePIE, and essentially allows for programmatic access to and redirection of TrackIR input data via Python scripting.

 

I then quickly wrote the following generic script which allows for binding of TrackIR axis input data beyond a given threshold to keys. I use it to bind my TrackIR roll axis to the keys "U" and "I", which I in turn then bind to "Lean Left" and "Lean Right" in game (Lean Toggle OFF). The key bind only gets triggered if the axis input data is either below -50 or above +50 respectively – which equals to a deadzone of 100 in the center of the axis. Key binds, axis and thresholds can easily be changed to other people's likings.

 

I don't know if this is of interest for anyone but thought I might as well share. The code can be found in this GitHub Gist, but I'll simply paste it here as well. Feel free to use it and ask any questions you might have here.

 

EDIT: I changed the script to allow for an arbitrary number of axis - threshold - key combinations.

# FreePIE TrackIR AxisToKey## Author: loenze (https://github.com/loenze)# Bind axis value beyond given threshold to key.## I wrote this for leaning in Squad,# but the script should work in any game with any action.## SQUAD forums discussion: http://goo.gl/mVh6E7## To configure your key binds simply add config lists with the according parameters# to the AxisToKeyConfig list at line 31. You may add as many as you wish there.## AxisToKeyConfig = [#     [trackIR.roll, Key.U, -50],#     [trackIR.roll, Key.I, 50]# ]## This example consists of two bindings for the TrackIR roll axis.# If the head is tilted to the left beyond a value of -50, the U key will be pressed.# Likewise for tilting to the right beyond a value of 50 and the I key.## Possible axis values are: trackIR.x, trackIR.y, trackIR.z, trackIR.pitch, trackIR.roll, trackIR.yaw# Available keys can be found here: https://github.com/AndersMalmgren/FreePIE/wiki/Reference## To find the right threshold values for you, you might want to turn on debugging for# FreePIE's Watch window by uncommenting line 77.# CONFIGURATION# Add lists consisting of [axis, key, threshold]AxisToKeyConfig = [    [trackIR.roll, Key.U, -50],    [trackIR.roll, Key.I, 50]]class AxisToKey:    def __init__(self, axis, key, threshold):        self.axis      = axis        self.key       = key        self.threshold = threshold        self.type      = 'pos' if threshold > 0 else 'neg'            def press(self):        keyboard.setKeyDown(self.key)        def release(self):        keyboard.setKeyUp(self.key)            def over_threshold(self):        if self.type == 'pos':            return False if self.axis < self.threshold else True        else:            return False if self.axis > self.threshold else True        def update(self):        self.press() if self.over_threshold() else self.release()AxisToKeyBindings = [AxisToKey(*c) for c in AxisToKeyConfig]class Debug:    info = ''        @staticmethod    def read(binding):        Debug.info += """Axis\t""" + str(binding.axis) + """Thres\t""" + str(binding.threshold) + """Key\t""" + str(binding.key) + """Status\t""" + ('PRESSED' if keyboard.getKeyDown(binding.key) else '') + """        """        diagnostics.watch(Debug.info)def update():    for binding in AxisToKeyBindings:        binding.update()        # UNCOMMENT FOLLOWING LINE FOR DEBUGGING        #Debug.read(binding)if starting:    trackIR.update += update

Share this post


Link to post
Share on other sites

Ok, question: does it trigger from rotating your head left and right, or from actually physically moving/pivoting/leaning your head left and right?

Question two: how does it play for you? :)

Share this post


Link to post
Share on other sites

1: My configuration triggers lean left when I physically tilt my head left a bit and vice versa.

2: It actually plays quite nice, although I'd need to test a bit more. Only tried for one game last night.

 

Since axis, dead zone and keys can be changed, people might even use this for other stuff, e.g. physically lean to right and have the map open up. I'm not saying this would be a good idea tho' :D Just made up an example...

Share this post


Link to post
Share on other sites

Thank you so much for making this! This is really wonderful and much appreciated.

I have been quickly testing this on the training ground with values at -5 and 5 (instead of -50 and 50) for a nice fast response and it just works.

Share this post


Link to post
Share on other sites

I'll get this out of the way, I'm an idiot.

 

However, do you have any idea if I could use something like this to bind lean to foot pedals? Since I have pedals and not TrackIr and the game doesn't support other peripherals at this point.

Share this post


Link to post
Share on other sites

Thanks ,OP! damn, i hope the devs bring in full track ir support. Re the previous post, ive thought the same re; rudder pedals assigned to lean keys, especially after seeing Dyslexi ,the Arma youtube fella using them for infantry leaning as well as rudder control in helo use.

Share this post


Link to post
Share on other sites

Gunna bump this over to hardware support forum. Cool topic OP, glad to see TrackIR make any inroads.

Share this post


Link to post
Share on other sites

Thx unfrail! :)

 

@LugNut: Yes, could be done (or at least tried) – provided that FreePIE recognizes your pedals. You'd probably just have to change the axis name from trackIR.roll to something that matches your input. I know nothing about rudder pedals and their respecitve axes tho', I might be mistaken.

 

@Hipporider: I don't see why you couldn't use this in RS:S as well. If the game allows for leaning via holding down a key (as opposed to toggle).

Share this post


Link to post
Share on other sites

Hmm, I'll have to poke around a bit, thanks.

Pedals for incremental lean are awesome in Arma, I was sad not to be able to get them to work in squad.

Share this post


Link to post
Share on other sites

I've been using this for a few days now and have had no need to return to button presses.

Thanks again.

 

Share this post


Link to post
Share on other sites

-download and install freepie

-download this script 

 

-

 

-start the trackir software

-start freepie, choose the trackir plugin function (settings/plugins)

-open the script file in freepie (and maybe edit the values to your liking as explained in the text of the script)

-choose 'run script'

 

-start the game and add U and I as leaning keys in the game settings (or change them to Q and E in the script)

-enjoy.

Share this post


Link to post
Share on other sites

FWIW, since the OP tickled my brain and with a little internet searching, I found a script to use with my CH pedals and it's manager. Left pedal, left incremental lean, right, right and with both depressed I run forward hands free. For those long slogs from base.  :)

 

Since it runs independently, it works in all games.

Share this post


Link to post
Share on other sites

I've been using this for a few days now and have had no need to return to button presses.

Thanks again.

 

You're welcome m8. Glad it works out well for you!

 

-download and install freepie

-download this script 

 

-

 

-start the trackir software

-start freepie, choose the trackir plugin function (settings/plugins)

-open the script file in freepie (and maybe edit the values to your liking as explained in the text of the script)

-choose 'run script'

 

-start the game and add U and I as leaning keys in the game settings (or change them to Q and E in the script)

-enjoy.

 

Thanks for chiming in! Much appreciated!

 

FWIW, since the OP tickled my brain and with a little internet searching, I found a script to use with my CH pedals and it's manager. Left pedal, left incremental lean, right, right and with both depressed I run forward hands free. For those long slogs from base.  :)

 

Since it runs independently, it works in all games.

 

Great, sounds awesome. Incremental lean in Squad?

 

I've been using this for a few days now and have had no need to return to button presses.

Thanks again.

 

Great, sounds awesome. Incremental lean in Squad?

Share this post


Link to post
Share on other sites

@DanMo: You're welcome m8. Glad it works well for you! And thanks for chiming in! Much appreciated!

 

@LugNut: Great, sounds awesome. Incremental lean in Squad?

Share this post


Link to post
Share on other sites

-download and install freepie

-download this script

-

-start the trackir software

-start freepie, choose the trackir plugin function (settings/plugins)

-open the script file in freepie (and maybe edit the values to your liking as explained in the text of the script)

-choose 'run script'

-start the game and add U and I as leaning keys in the game settings (or change them to Q and E in the script)

-enjoy.

Thanks for that!

FWIW, since the OP tickled my brain and with a little internet searching, I found a script to use with my CH pedals and it's manager. Left pedal, left incremental lean, right, right and with both depressed I run forward hands free. For those long slogs from base. :)

Since it runs independently, it works in all games.

That's good to hear that incremental lean is possible with the pedals.

Share this post


Link to post
Share on other sites

I'll double check that it truly is incremental lean, I'm so used to full incremental in ARMA, that my head might be telling me that it is. If that makes sense. I feel like I can peek out slower at any rate, I'm still adjusting the script to get the feel right, so we'll see how much I can get out of it, but at the very least, I'm happy not to have it bound to keys. 

Share this post


Link to post
Share on other sites

I know incremental lean via pedals exists in arma, as Dyslexi shows it on one of his videos. I hope it can be done on Squad too

Share this post


Link to post
Share on other sites

Nope, no incremental lean, I was mistaken. I hope when TrackIR is implemented it will be just a matter of assigning keys like in ARMA.

Share this post


Link to post
Share on other sites

dumb noob question ,i know,but i cant get this working. The code is all the text in the window or only some of it in the window?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×