Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Edited dual-axis output program for E:D, by lemurcan, credit to Andrea Spada for original program
- # Requirements: vJoy and freePie
- # This edit fixes a few fundamental issues with Andrea's program, most notably the behavior of the
- # relative-mouse emulation.
- # 1. Previously in the program, relative mouse was emulated with a "fixed" return to center rate. This meant that for
- # minor movements amounting to less than this fixed value, they would be cancelled out by the next poll of the program.
- # This severely hindered fine control and combined with the following flaw, did not accurately emulate the game's
- # relative mouse function.
- # 2. The previous relative mouse implementation incorporated an "idle check" that would make it so the return force only
- # activated when there was no new movement. It did this by having alternating checks, one at a 30ms poll and another 60ms;
- # this effectively meant that the return motion would only occur once your mouse had been still for 30ms. This, as per my
- # own experimental testing with the official in-game relative mouse, is also inaccurate. The ingame return force is always
- # active and has no waiting-for-idle component.
- # 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
- # input delay and be on-par with the standard for most "gaming-grade" mice. This also helps account, in my view, for Python's
- # timing inconsistencies. Do note that the logarithmic curve implemented for relative mouse is scaled accordingly, and
- # adjusting this poll rate will necessitate an inverse multiplication of rel_factor.
- #
- # Short documentation of relevant variables:
- # absolute_sens and relative_sens adjust each axes' mouse sensitivity in a linear fashion
- # pradius is the absolute mouse deadzone; do note that this is respective to the vjoy output, which is 0 to +- 16k
- # smart_speed is the rate of return within the absolute mouse deadzone
- # rel_factor is the logarithmic factor for the constant relative mouse return force. 200 is roughly equal to max relative mouse
- # in-game.
- # curve determines the steepness of the mild exponential curve per Andrea's absolute mouse implementation; implementation is
- # not entirely clear and the default of 3 seems functional and noninterfering with gameplay; may implement true linear later.
- #
- # 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
- # hard-center the mouse; think menu or flight mode toggles. Follow the or statement structure for adding additional keys, FreePIE
- # should auto-fill options for the keys as you type.
- # Original credit below:
- #
- # Title: Trackball/Mouse to Analog Axis for Elite: Dangerous, with "Relative Mouse" additional axis.
- # Author: Andrea Spada
- # Version: 3.3
- #
- # Features: Simulate analog axis from mouse for yaw and pitch. It use vJoy.
- #
- # Each mouse direction is mapped to two axis. So, for lateral movement, we have both X and RX axis.
- # Vertical movements are mapped to Y and RY.
- #
- # X and Y give absolute mouse movement, like an analog joystick. They are smart auto-centering when near the center.
- # The range of this self-centering (mostly for aim purpouse) is defined by a customizable radius.
- # They also has a small exponential curve, so near zaro they give a smooth movement. The farther, the coarser.
- #
- # RX and RY axis give relative mouse movement, not unlike a directional pad. It's perfect for flying FA-Off, or for
- # more precise situations: mining, landing, etc...
- #
- # Both movement can be easily tweaked in sensitivity.
- from System import Int16
- if starting:
- # Timer, for auto-centering
- system.setThreadTiming(TimingTypes.HighresSystemTimer)
- system.threadExecutionInterval = 1 # loop delay
- # Devices and axis initializing
- max = Int16.MaxValue*0.5+0.5 # 16384
- min = -Int16.MaxValue*0.5-0.5 # -16384
- mouseX = 0
- mouseY = 0
- mouseXcurved = 0
- mouseYcurved = 0
- mouseRX = 0
- mouseRY = 0
- # Coordinates for self centering
- a = 0
- b = 0
- c = 0
- d = 0
- #Flag for toggling
- toggle = False
- global absolute_sens, relative_sens, smart_speed, rel_speed, curve, pradius, nradius
- absolute_sens = 30 # absolute mouse mode sensitivity
- relative_sens = 30 # relative mouse mode sensitivity
- smart_speed = 25 # smart-centering speed, in absolute mouse mode
- rel_factor = 200 # hard-centering factor, in relative mouse mode
- curve = 3 # exponential factor for the axis curve
- pradius = 50 # smart self-centering radius, for absolute mouse
- nradius = pradius - (pradius *2) #
- #
- ###
- ##### Mouse
- # axis definition
- mouseX += mouse.deltaX * absolute_sens # absolute mouse, lateral
- mouseY += mouse.deltaY * absolute_sens # vertical
- mouseRX += mouse.deltaX * relative_sens # relative mouse, lateral
- mouseRY += mouse.deltaY * relative_sens # vertical
- # define a range and limit the axis values
- if (mouseX > max):
- mouseX = max
- elif (mouseX < min):
- mouseX = min
- if (mouseY > max):
- mouseY = max
- elif (mouseY < min):
- mouseY = min
- if (mouseRX > max):
- mouseRX = max
- elif (mouseRX < min):
- mouseRX = min
- if (mouseRY > max):
- mouseRY = max
- elif (mouseRY < min):
- mouseRY = min
- #
- ##
- ### Absolute Mouse
- # smart centering
- if (mouseX < pradius) and (mouseX > 0):
- mouseX = mouseX - smart_speed
- elif (mouseX > nradius) and (mouseX < 0):
- mouseX = mouseX + smart_speed
- if (mouseY < pradius) and (mouseY > 0):
- mouseY = mouseY - smart_speed
- elif (mouseY > nradius) and (mouseY < 0):
- mouseY = mouseY + smart_speed
- # lightly exponential curved axis
- if (mouseX > 0):
- mouseXcurved = math.floor((math.sqrt(( mouseX ** curve )) /2 ) / 64)
- if (mouseX < 0):
- mouseXn = mouseX * -1
- mouseXcurved = math.floor((math.sqrt(( mouseXn ** curve )) / 2 ) * -1 / 64)
- if (mouseY > 0):
- mouseYcurved = math.floor((math.sqrt(( mouseY ** curve )) /2 ) / 64)
- if (mouseY < 0):
- mouseYn = mouseY * -1
- mouseYcurved = math.floor((math.sqrt(( mouseYn ** curve )) / 2 ) * -1 / 64)
- # Hard Mouse Centering (By press an hotkey)
- # Useful when you need your mouse to return to the center, like when you switch workspaces or exiting galaxy map...
- if toggle or keyboard.getKeyDown(Key.LeftControl) or keyboard.getKeyDown(Key.Backspace):
- mouseX = 0
- mouseY = 0
- mouseXcurved = 0
- mouseYcurved = 0
- # Toggle hotkey
- if keyboard.getPressed(Key.DownArrow) or keyboard.getPressed(Key.UpArrow):
- if toggle:
- toggle = False
- else:
- toggle = True
- # Mouse Output - Absolute Movement
- if not toggle:
- vJoy[0].x = filters.deadband(mouseXcurved, 10)
- vJoy[0].y = filters.deadband(mouseYcurved, 10)
- else:
- vJoy[0].x = 0
- vJoy[0].y = 0
- #
- ##
- ### Relative Mouse
- # Self Centering Alternate Axis
- if mouseRX != 0:
- mouseRX -= (mouseRX / rel_factor)
- if mouseRY != 0:
- mouseRY -= (mouseRY / rel_factor)
- # Mouse Output - Relative Movement
- if not toggle:
- vJoy[0].rx = filters.deadband(mouseRX, 50)
- vJoy[0].ry = filters.deadband(mouseRY, 50)
- else:
- vJoy[0].rx = 0
- vJoy[0].ry = 0
- #####
- ###
- #
- #
- ###
- ##### Diagnostics
- # Mouse
- diagnostics.watch(vJoy[0].x)
- diagnostics.watch(vJoy[0].y)
- diagnostics.watch(vJoy[0].rx)
- diagnostics.watch(vJoy[0].ry)
- diagnostics.watch(mouse.deltaX)
- diagnostics.watch(mouse.deltaY)
- diagnostics.watch(toggle)
Advertisement
Add Comment
Please, Sign In to add comment