Guest User

lemurcan FA-off relative toggle ver 1.1

a guest
Sep 19th, 2022
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.54 KB | None | 0 0
  1. # Edited dual-axis output program for E:D, by lemurcan, credit to Andrea Spada for original program
  2. # Requirements: vJoy and freePie
  3. # This edit fixes a few fundamental issues with Andrea's program, most notably the behavior of the
  4. # relative-mouse emulation.
  5. # 1. Previously in the program, relative mouse was emulated with a "fixed" return to center rate. This meant that for
  6. # minor movements amounting to less than this fixed value, they would be cancelled out by the next poll of the program.
  7. # This severely hindered fine control and combined with the following flaw, did not accurately emulate the game's
  8. # relative mouse function.
  9. # 2. The previous relative mouse implementation incorporated an "idle check" that would make it so the return force only
  10. # activated when there was no new movement. It did this by having alternating checks, one at a 30ms poll and another 60ms;
  11. # this effectively meant that the return motion would only occur once your mouse had been still for 30ms. This, as per my
  12. # own experimental testing with the official in-game relative mouse, is also inaccurate. The ingame return force is always
  13. # active and has no waiting-for-idle component.
  14. # 3. This is a relatively minor flaw but the previous program only polled at a 4ms rate; I have upped this to 1ms to improve
  15. # input delay and be on-par with the standard for most "gaming-grade" mice. This also helps account, in my view, for Python's
  16. # timing inconsistencies. Do note that the logarithmic curve implemented for relative mouse is scaled accordingly, and
  17. # adjusting this poll rate will necessitate an inverse multiplication of rel_factor.
  18. #
  19. # Short documentation of relevant variables:
  20. # absolute_sens and relative_sens adjust each axes' mouse sensitivity in a linear fashion
  21. # pradius is the absolute mouse deadzone; do note that this is respective to the vjoy output, which is 0 to +- 16k
  22. # smart_speed is the rate of return within the absolute mouse deadzone
  23. # rel_factor is the logarithmic factor for the constant relative mouse return force. 200 is roughly equal to max relative mouse
  24. # in-game.
  25. # curve determines the steepness of the mild exponential curve per Andrea's absolute mouse implementation; implementation is
  26. # not entirely clear and the default of 3 seems functional and noninterfering with gameplay; may implement true linear later.
  27. #
  28. # Lower in the program are values to be edited according to your keybinds: lines 170 and 177 have an entry points for keys that will
  29. # hard-center the mouse; think menu or flight mode toggles. Follow the or statement structure for adding additional keys, FreePIE
  30. # should auto-fill options for the keys as you type.
  31.  
  32.  
  33. # Original credit below:
  34. #
  35. # Title: Trackball/Mouse to Analog Axis for Elite: Dangerous, with "Relative Mouse" additional axis.
  36. # Author: Andrea Spada
  37. # Version: 3.3
  38. #
  39. # Features: Simulate analog axis from mouse for yaw and pitch. It use vJoy.
  40. #
  41. # Each mouse direction is mapped to two axis. So, for lateral movement, we have both X and RX axis.
  42. # Vertical movements are mapped to Y and RY.
  43. #
  44. # X and Y give absolute mouse movement, like an analog joystick. They are smart auto-centering when near the center.
  45. # The range of this self-centering (mostly for aim purpouse) is defined by a customizable radius.
  46. # They also has a small exponential curve, so near zaro they give a smooth movement. The farther, the coarser.
  47. #
  48. # RX and RY axis give relative mouse movement, not unlike a directional pad. It's perfect for flying FA-Off, or for
  49. # more precise situations: mining, landing, etc...
  50. #
  51. # Both movement can be easily tweaked in sensitivity.
  52.  
  53.  
  54.  
  55.  
  56. from System import Int16
  57.  
  58. if starting:
  59.     # Timer, for auto-centering
  60.     system.setThreadTiming(TimingTypes.HighresSystemTimer)
  61.     system.threadExecutionInterval = 1 # loop delay
  62.    
  63.     # Devices and axis initializing
  64.     max =  Int16.MaxValue*0.5+0.5   #  16384
  65.     min = -Int16.MaxValue*0.5-0.5   # -16384
  66.     mouseX    = 0
  67.     mouseY    = 0
  68.     mouseXcurved = 0
  69.     mouseYcurved = 0
  70.     mouseRX    = 0
  71.     mouseRY    = 0
  72.    
  73.     # Coordinates for self centering
  74.     a = 0
  75.     b = 0
  76.     c = 0
  77.     d = 0
  78.    
  79.     #Flag for toggling
  80.     toggle = False
  81.    
  82.    
  83. global absolute_sens, relative_sens, smart_speed, rel_speed, curve, pradius, nradius
  84.  
  85.  
  86. absolute_sens = 30            # absolute mouse mode sensitivity
  87. relative_sens = 30            # relative mouse mode sensitivity
  88. smart_speed = 25             # smart-centering speed, in absolute mouse mode
  89. rel_factor = 200            # hard-centering factor, in relative mouse mode
  90.  
  91.  
  92. curve = 3                 # exponential factor for the axis curve
  93.  
  94.  
  95. pradius = 50                      # smart self-centering radius, for absolute mouse
  96. nradius = pradius - (pradius *2)    #
  97.  
  98.  
  99. #
  100. ###
  101. ##### Mouse
  102.  
  103.  
  104. # axis definition
  105. mouseX += mouse.deltaX * absolute_sens      # absolute mouse, lateral
  106. mouseY += mouse.deltaY * absolute_sens      #                 vertical
  107. mouseRX += mouse.deltaX * relative_sens     # relative mouse, lateral
  108. mouseRY += mouse.deltaY * relative_sens     #                 vertical
  109.  
  110.  
  111. # define a range and limit the axis values
  112. if (mouseX > max):
  113.   mouseX = max
  114. elif (mouseX < min):
  115.   mouseX = min
  116.  
  117.  
  118. if (mouseY > max):
  119.   mouseY = max
  120. elif (mouseY < min):
  121.   mouseY = min
  122.  
  123.  
  124. if (mouseRX > max):
  125.   mouseRX = max
  126. elif (mouseRX < min):
  127.   mouseRX = min
  128.  
  129.  
  130. if (mouseRY > max):
  131.   mouseRY = max
  132. elif (mouseRY < min):
  133.   mouseRY = min
  134.  
  135.  
  136. #
  137. ##
  138. ### Absolute Mouse
  139.  
  140.  
  141. # smart centering
  142. if (mouseX < pradius) and (mouseX > 0):
  143.     mouseX = mouseX - smart_speed
  144. elif (mouseX > nradius) and (mouseX < 0):
  145.     mouseX = mouseX + smart_speed
  146.  
  147.  
  148. if (mouseY < pradius) and (mouseY > 0):
  149.     mouseY = mouseY - smart_speed
  150. elif (mouseY > nradius) and (mouseY < 0):
  151.     mouseY = mouseY + smart_speed
  152.  
  153.  
  154. # lightly exponential curved axis
  155. if (mouseX > 0):
  156.     mouseXcurved = math.floor((math.sqrt(( mouseX ** curve )) /2 ) / 64)
  157. if (mouseX < 0):
  158.     mouseXn = mouseX * -1
  159.     mouseXcurved = math.floor((math.sqrt(( mouseXn ** curve )) / 2 ) * -1 / 64)
  160.  
  161.  
  162. if (mouseY > 0):
  163.     mouseYcurved = math.floor((math.sqrt(( mouseY ** curve )) /2 ) / 64)
  164. if (mouseY < 0):
  165.     mouseYn = mouseY * -1
  166.     mouseYcurved = math.floor((math.sqrt(( mouseYn ** curve )) / 2 ) * -1 / 64)
  167.  
  168.  
  169. # Hard Mouse Centering (By press an hotkey)
  170. # Useful when you need your mouse to return to the center, like when you switch workspaces or exiting galaxy map...
  171. if toggle or keyboard.getKeyDown(Key.LeftControl) or keyboard.getKeyDown(Key.Backspace):
  172.     mouseX = 0
  173.     mouseY = 0
  174.     mouseXcurved = 0
  175.     mouseYcurved = 0
  176.  
  177. # Toggle hotkey
  178. if keyboard.getPressed(Key.DownArrow) or keyboard.getPressed(Key.UpArrow):
  179.     if toggle:
  180.         toggle = False
  181.     else:
  182.         toggle = True
  183.  
  184.  
  185. # Mouse Output - Absolute Movement
  186. if not toggle:
  187.     vJoy[0].x = filters.deadband(mouseXcurved, 10)
  188.     vJoy[0].y = filters.deadband(mouseYcurved, 10)
  189. else:
  190.     vJoy[0].x = 0
  191.     vJoy[0].y = 0
  192.  
  193.  
  194. #
  195. ##
  196. ### Relative Mouse
  197.  
  198.  
  199. # Self Centering Alternate Axis
  200.  
  201. if mouseRX != 0:
  202.     mouseRX -= (mouseRX / rel_factor)
  203. if mouseRY != 0:
  204.     mouseRY -= (mouseRY / rel_factor)
  205.    
  206.  
  207.  
  208. # Mouse Output - Relative Movement
  209. if not toggle:
  210.     vJoy[0].rx = filters.deadband(mouseRX, 50)
  211.     vJoy[0].ry = filters.deadband(mouseRY, 50)
  212. else:
  213.     vJoy[0].rx = 0
  214.     vJoy[0].ry = 0
  215.  
  216.  
  217. #####
  218. ###
  219. #
  220.  
  221.  
  222.  
  223.  
  224. #
  225. ###
  226. ##### Diagnostics
  227.  
  228.  
  229. # Mouse
  230. diagnostics.watch(vJoy[0].x)
  231. diagnostics.watch(vJoy[0].y)
  232. diagnostics.watch(vJoy[0].rx)
  233. diagnostics.watch(vJoy[0].ry)
  234.  
  235. diagnostics.watch(mouse.deltaX)
  236. diagnostics.watch(mouse.deltaY)
  237. diagnostics.watch(toggle)
  238.  
Advertisement
Add Comment
Please, Sign In to add comment