I have been using FreePie to hook into my TrackIr to enable leaning (Q and E keypress) in games that don't support TrackIr natively.
But it, or the script I am using, uses way too much CPU power
Up to 14% on my i5 2500k (OC)
Does anyone have any tips to share on how to reduce it? I would really appreciate it.
I've already commented out the 'diagnostics.watch', but that doesn't make a noticeable difference.
Code: Select all
# 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.Q, -50],
# [trackIR.roll, Key.E, 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.Q, -50],
[trackIR.roll, Key.E, 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