Freespace 2

Freespace 2

Not enough ratings
FreePIE XBox360 Controller Script
By TamaSaga
A casual port of a GlovePIE script that I found online. This guide is mainly aimed at programmers.

http://www.hard-light.net/forums/index.php?topic=85880.10;wap2

If you're not afraid to program, you can customize your XBox360 far more than the original game options will allow you to. Like holding buttons can make them do an alternate action. The script here is just an example. I've tested and all buttons work as they should. Unfortunately, the script will require additional modifications before it's tuned for performance.

If you aren't familiar with FreePIE or GlovePIE, they are PC programs that run in the background. When activated, they can capture buttons, movements, and actions for devices like the XBox360 controller or Track IR headset and map them to keyboard keys, mouse movements, or other input device actions.

I don't know if the script can be modified to activate only when a specific game is started, so you'll have to bear with opening FreePIE, starting the script, and then starting FreeSpace 2. And then shutting everything down manually after you're done with FreeSpace, otherwise the script will continue to remain active.

More about FreePIE:
http://andersmalmgren.github.io/FreePIE/
   
Award
Favorite
Favorited
Unfavorite
Instructions
Copy and paste the Python code found in the Code section.
The Code
import time class Touch: def __init__(self, p_Delay = 100): self.m_StartTime = -1 self.m_CurrentTime = -1 self.m_Press = False self.m_Active = False self.m_Delay = p_Delay self.m_BtnDown = False # Whether a button is being held. self.m_NewStart = True def process(self, p_Button, p_Time): self.m_BtnDown = p_Button if p_Button: self.start(p_Time) else: self.reset() def IsButtonDown(self): return self.m_BtnDown def IsPressed(self): l_Press = self.m_Press self.m_Press = False return l_Press def IsLongPressed(self): if (self.m_Active) and ((self.m_CurrentTime - self.m_StartTime) * 1000 > self.m_Delay): self.m_Active = False return True else: return False def start(self, p_CurrentTime): if self.m_NewStart: self.m_StartTime = p_CurrentTime self.m_Active = True self.m_NewStart = False else: self.m_CurrentTime = p_CurrentTime def reset(self): if (self.m_Active) and ((self.m_CurrentTime - self.m_StartTime) * 1000 < self.m_Delay): self.m_Press = True self.m_Active = False self.m_StartTime = -1 self.m_CurrentTime = -1 self.m_NewStart = True if starting: var_sensitivity = 0.7 var_gain = 2 var_deadzone = 0.2 Btn_A = Touch(1000) Btn_B = Touch(1000) Btn_X = Touch(1000) Btn_Y = Touch(1000) Btn_LeftShoulder = Touch(1000) Btn_RightShoulder = Touch(1000) Btn_Up = Touch(1000) Btn_Down = Touch(1000) Btn_Left = Touch(1000) Btn_Right = Touch(1000) Btn_LeftThumb = Touch(1000) Btn_RightThumb = Touch(1000) Btn_Start = Touch(1000) Btn_Back = Touch(1000) Time_Val = time.clock() Btn_A.process(xbox360[0].a, Time_Val) Btn_B.process(xbox360[0].b, Time_Val) Btn_X.process(xbox360[0].x, Time_Val) Btn_Y.process(xbox360[0].y, Time_Val) Btn_LeftShoulder.process(xbox360[0].leftShoulder, Time_Val) Btn_RightShoulder.process(xbox360[0].rightShoulder, Time_Val) Btn_Up.process(xbox360[0].up, Time_Val) Btn_Down.process(xbox360[0].down, Time_Val) Btn_Left.process(xbox360[0].left, Time_Val) Btn_Right.process(xbox360[0].right, Time_Val) Btn_LeftThumb.process(xbox360[0].leftThumb, Time_Val) Btn_RightThumb.process(xbox360[0].rightThumb, Time_Val) Btn_Start.process(xbox360[0].start, Time_Val) Btn_Back.process(xbox360[0].back, Time_Val) var_left_stick_X = filters.deadband(xbox360[0].leftStickX, var_deadzone) var_left_stick_Y = filters.deadband(xbox360[0].leftStickY, var_deadzone) var_right_stick_X = filters.deadband(xbox360[0].rightStickX, var_deadzone) var_right_stick_Y = filters.deadband(xbox360[0].rightStickY, var_deadzone) # ===================== Flight ============================ # Left Stick: Pitch and Yaw mouse.deltaX = cmp(var_left_stick_X, 0) * pow(var_left_stick_X * var_sensitivity, var_gain); mouse.deltaY = -cmp(var_left_stick_Y, 0) * pow(var_left_stick_Y * var_sensitivity, var_gain); # Right Stick - X: Roll keyboard.setKey(Key.NumberPad9, var_right_stick_X > var_deadzone) keyboard.setKey(Key.NumberPad7, var_right_stick_X < -var_deadzone) # Right Stick - Y: Throttle # At Max Throttle, Afterburner # At Min Throttle, Set Throttle to Zero # At Near-Max Throttle, Set Throttle To Max # Rest of Throttle Range, Temporarily Increase or Decrease Throttle var_right_stick_Y = filters.deadband(xbox360[0].rightStickY, var_deadzone) keyboard.setKey(Key.A, var_right_stick_Y > 0.5) keyboard.setKey(Key.Z, var_right_stick_Y < -0.5) keyboard.setKey(Key.Backslash, var_right_stick_Y > 0.8) keyboard.setKey(Key.Tab, var_right_stick_Y > 0.9) keyboard.setKey(Key.Backspace, var_right_stick_Y < -0.8) # Btn Right Thumb: # When Pressed, Match speed # When Held, Auto-Match Speed if (not Btn_LeftShoulder.IsButtonDown()): keyboard.setKey(Key.M, Btn_RightThumb.IsPressed()) if (Btn_RightThumb.IsLongPressed()): keyboard.setPressed(Key.LeftAlt) keyboard.setPressed(Key.M) # ===================== Energy Distribution ============================ if (Btn_LeftShoulder.IsButtonDown()): # DPad Up + Left Shoulder: # If Pressed, Increase Power to Shields # If Held, Decrease Power to Shields keyboard.setKey(Key.Home, Btn_Up.IsPressed()) keyboard.setKey(Key.End, Btn_Up.IsLongPressed()) # DPad Right + Left Shoulder: # If Pressed, Increase Power to Weapons # If Held, Decrease Power to Weapons keyboard.setKey(Key.Insert, Btn_Right.IsPressed()) keyboard.setKey(Key.Delete, Btn_Right.IsLongPressed()) # DPad Left + Left Shoulder: # If Pressed, Increase Power to Engines # If Held, Equalize power to all systems keyboard.setKey(Key.PageUp, Btn_Left.IsPressed()) if (Btn_Left.IsLongPressed()): keyboard.setPressed(Key.LeftAlt) keyboard.setPressed(Key.D) # Right Stick + Left Shoulder: # Augment Shields in the given direction keyboard.setKey(Key.UpArrow, var_right_stick_Y > 0.5) keyboard.setKey(Key.DownArrow, var_right_stick_Y < -0.5) keyboard.setKey(Key.LeftArrow, var_right_stick_X < -0.5) keyboard.setKey(Key.RightArrow, var_right_stick_X > 0.5) # Right Thumb + Left Shoulder: # Equalize all 4 shield quadrants keyboard.setKey(Key.Q, Btn_RightThumb.IsPressed()) # ===================== Targeting ============================ # Btn Y: # If Pressed, Next Target # If Held, Select Target in Reticle keyboard.setKey(Key.T, Btn_Y.IsPressed()) keyboard.setKey(Key.Y, Btn_Y.IsLongPressed()) # Btn X: # If Pressed, Next Hostile Target # If Held, Engage Auto Target keyboard.setKey(Key.H, Btn_X.IsPressed()) if (Btn_X.IsLongPressed()): keyboard.setPressed(Key.LeftAlt) keyboard.setPressed(Key.H) # Btn B: # If Pressed, Next Escort Target keyboard.setKey(Key.E, Btn_B.IsPressed()) # DPad Right # Next Sub-System if pressed if (not Btn_LeftShoulder.IsButtonDown()): keyboard.setKey(Key.S, Btn_Right.IsPressed()) # ===================== Weapons ============================ # Right Shoulder: # When Pressed, Switch Between Primary Weapons # When Pressed w/ Left Shoulder, Switch Between Secondary Weapons # When Held w/ Left Shoulder, Toggle Double Fire if (Btn_LeftShoulder.IsButtonDown()): if (Btn_RightShoulder.IsLongPressed()): keyboard.setPressed(Key.LeftShift) keyboard.setPressed(Key.Slash) else: keyboard.setKey(Key.Slash, Btn_RightShoulder.IsPressed()) else: keyboard.setKey(Key.Period, Btn_RightShoulder.IsPressed()) # Left Trigger: # When Pressed, Fire Secondary Weapon keyboard.setKey(Key.Space, xbox360[0].leftTrigger) # Right Trigger: # When Pressed, Fire Primary Weapon # When Pressed w/ Left Shoulder - Countermeasures if (Btn_LeftShoulder.IsButtonDown()): keyboard.setKey(Key.X, xbox360[0].rightTrigger) else: keyboard.setKey(Key.LeftControl, xbox360[0].rightTrigger) # ===================== Communication ============================ # Btn Back: # Communication Menu # When Held, Request Resupply keyboard.setKey(Key.C, Btn_Back.IsPressed()) if (Btn_Back.IsLongPressed()): keyboard.setPressed(Key.LeftShift) keyboard.setPressed(Key.R) # ===================== Miscellaneous ============================ # Btn A: Left Mouse Click (Can also be used, but not recommended for firing primary weapons) mouse.leftButton = xbox360[0].a # Btn Start: # When Pressed - In-Game Menu (Escape Button). # When Held - HyperJump # When Pressed w/ Left Shoulder - Options Menu if (Btn_LeftShoulder.IsButtonDown()): keyboard.setKey(Key.F2, Btn_Start.IsPressed()) else: keyboard.setKey(Key.Escape, Btn_Start.IsPressed()) if (Btn_Start.IsLongPressed()): keyboard.setPressed(Key.LeftAlt) keyboard.setPressed(Key.J) # Btn Left Thumb: # When Pressed, Cycle Radar Ranges keyboard.setKey(Key.Apostrophe, Btn_LeftThumb.IsPressed())
2 Comments
Texan Nationalist Feb 21, 2016 @ 12:56pm 
Here is the code:
keyboard.setKey(Key.Z, Btn_A.IsPressed())
keyboard.setKey(Key.X, Btn_B.IsPressed())
keyboard.setKey(Key.Escape, Btn_Start.IsPressed())
keyboard.setKey(Key.Backspace, Btn_Back.IsPressed())
keyboard.setKey(Key.A, Btn_LeftThumb.IsPressed())
keyboard.setKey(Key.S, Btn_RightThumb.IsPressed())
keyboard.setKey(Key.UpArrow, var_left_stick_Y > 0.5)
keyboard.setKey(Key.DownArrow, var_left_stick_Y < -0.5)
keyboard.setKey(Key.LeftArrow, var_left_stick_X < -0.5)
keyboard.setKey(Key.RightArrow, var_left_stick_X > 0.5)
Texan Nationalist Feb 21, 2016 @ 12:56pm 
I am basing an incredibly simple code on yours, but when I run it it tells me "name 'Btn_A' is not defined"