Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- ##### What is this #####
- # I made a simple python script to help with boosting away from interdiction's and bombing/rocketing the titan.
- # What this script does is very simple. It repeatedly presses your boost key while you are holding it down.
- # And if Scroll Lock is toggled on, then Right Mouse Button becomes full auto.
- #
- # If you are using an SCO FSD then i have an alternate version of the main() function for you to use.
- # It changes Scroll Lock to act as a global on/off key for the whole script.
- # Its a little more tedious to use since you need to turn the script on when using thrusters (if you want auto-boost)
- # and definitely off when using supercruise. I think this made SCO FSD even more annoying to run xD
- #
- # For reference here is my titan-bomber fire groups indicating what RMB is assigned to.
- # In firegroup C and D i use '(2)' for Nanite Torpedo Pylon and AX Missile Rack.
- # To prevent TG Pulse Neutraliser from discharging incorrectly prior to entering the titan cloud
- # keep Scroll Lock off until you are through the caustic cloud. After that you can keep Scroll Lock on.
- # The Nanite Torpedo Pylon will not fire until you have a lock,
- # and it feels like firing, so you can focus on flying + targeting with RMB held down and it will auto-click for you.
- # Also the AX Missile Rack is full auto now for when its time to shoot the exposed core :D
- #
- # A B C D E
- # Beam Laser -------------------------------1-------1---------------
- # AX Missile Rack ----------------------------------2---------------
- # AX Missile Rack ----------------------------------2---------------
- # AX Missile Rack ----------------------------------2---------------
- # Nanite Torpedo Pylon ---------------------2-----------------------
- # Repair Limpet --------------------------------------------1-------
- # TG Pulse Neutraliser -------------2-------------------------------
- # Enhanced Xeno Scanner ----2---------------------------------------
- # Heatsink ---------------------------------------------------------
- # Caustic Sink Launcher ------------1-------------------------------
- # Data Link Scanner --------2---------------------------------------
- # Comp. Scanner ------------2---------------------------------------
- # D-Scanner ----------------1---------------------------------------
- ##### Installation #####
- # To run this script you need Python installed. After that run cmd as administrator > [pip install pynput] because that library is also needed.
- # Save this script as a .py file, e.g. "Titan Script.py" and double click the file to run it.
- # Also, unless you are also using Caps Lock as a boost key then you'll probably want to mod this line "boost_button = Key.caps_lock".
- ##### How to use this script when titan bombing #####
- # 1. When you jump into a titan system make sure Scroll Lock is toggled OFF (LED off).
- # This disables the RMB autofire feature.
- # We don't want to accidentally autofire whatever you have bound to mouse-2 right now, e.g. TG Pulse Neutraliser, Heatsinks, Caustic sinks etc.
- #
- # 2. When interdicted keep your boost key held down with all pips to engines.
- # No need to spam the boost key like you're having a seizure, the script will handle it.
- #
- # 3. When you are through the malestrom cloud and at the titan, toggle ON Scroll Lock (LED on) to enable RMB autofire.
- #
- # 4. Switch to your Beam Laser + Nanite Torpedo fire group and commence to torpedo the thermal vents.
- # Lock on to thermal vents and hold RMB. The Nanite Torpedo will only fire when you get close.
- # No need to spam RMB.
- #
- # 5. Now switch to your Beam Laser + AX Missile Rack fire group and fly to the exposed core.
- # Your rockets will fire as fast as the game allows, just hold down RMB and watch the fireworks.
- #
- # 6. Fly away to avoid the blue radiation attack, and repeat steps 4+.
- import time
- def sleep(milliseconds):
- time.sleep(milliseconds / 1000)
- # Windows: $ pip install pynput
- # SOURCE: https://pypi.org/project/pynput/
- import pynput
- from pynput.keyboard import Key, KeyCode, Controller as KeyboardController
- from pynput.mouse import Button, Controller as MouseController
- shoot_button = Button.right # My Nanite Torpedo Pylon & AX Missile Rack button. If you use something else, then edit this line.
- boost_button = Key.caps_lock # My boost key [Flight Miscellaneous > Engine boost]. If you use something else, then edit this line.
- #boost_button = Key.tab # If you use Tab to boost then uncomment this line.
- #boost_button = KeyCode.from_char('b') # If you use a letter key like 'B' to boost then uncomment this line.
- ##### Key status #####
- pressed_inputs = {
- shoot_button : False,
- boost_button : False,
- }
- import ctypes
- # GetKeyState(...) returns the status of the key. 1 if the key is toggled on, else 0.
- def is_capslock_on():
- return ctypes.windll.user32.GetKeyState(0x14)
- def is_numlock_on():
- return ctypes.windll.user32.GetKeyState(0x90)
- def is_scrolllock_on():
- return ctypes.windll.user32.GetKeyState(0x91)
- ##### Keyboard Hook #####
- # This runs every time a key press is detected.
- # When you hold down a key, the operating system will repeat pressing the key at the key repeat rate which is why on_press is called multiple times.
- def on_press(key):
- # print('Pressed', key)
- if key in pressed_inputs:
- pressed_inputs[key] = True
- # This runs every time a key release is detected.
- def on_release(key):
- # print('Released', key)
- if key in pressed_inputs:
- pressed_inputs[key] = False
- LLKHF_INJECTED = 0x10
- # msg represents the Windows message associated with the event.
- # data provides additional information related to the event. Its a MSLLHOOKSTRUCT. https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-msllhookstruct
- def keyboard_win32_event_filter(msg, data):
- # If this callback returns True, the event will be allowed to propagate normally throughout the system.
- # If this callback returns False, the event will not be propagated to the listener callback.
- # If listener.suppress_event() is called, the event is suppressed system wide. https://readthedocs.org/projects/pynput/downloads/pdf/latest/ https://pynput.readthedocs.io/en/latest/faq.html
- # Prevent simulated key presses from triggering keyboard-event callbacks.
- return not data.flags & LLKHF_INJECTED
- keyboard_listener = pynput.keyboard.Listener(
- on_press=on_press,
- on_release=on_release,
- win32_event_filter=keyboard_win32_event_filter)
- keyboard_listener.start()
- ##### Mouse Hook #####
- # This runs when a mouse click or release is detected.
- def on_click(x, y, button, pressed):
- # print('Clicked' if pressed else 'Released', button)
- if button in pressed_inputs:
- pressed_inputs[button] = pressed
- LLMHF_INJECTED = 0x01
- # msg represents the Windows message associated with the event.
- # data provides additional information related to the event. Its a MSLLHOOKSTRUCT. https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-msllhookstruct
- def mouse_win32_event_filter(msg, data):
- # If this callback returns True, the event will be allowed to propagate normally throughout the system.
- # If this callback returns False, the event will not be propagated to the listener callback.
- # If listener.suppress_event() is called, the event is suppressed system wide. https://readthedocs.org/projects/pynput/downloads/pdf/latest/ https://pynput.readthedocs.io/en/latest/faq.html
- # Prevent simulated mouse clicks from triggering mouse-event callbacks.
- return not data.flags & LLMHF_INJECTED
- mouse_listener = pynput.mouse.Listener(
- on_click=on_click,
- win32_event_filter=mouse_win32_event_filter)
- mouse_listener.start()
- ##### MNK Simulation #####
- keyboard_controller = KeyboardController()
- mouse_controller = MouseController()
- def get_controller(mnkInput):
- if isinstance(mnkInput, (Key, KeyCode)):
- return keyboard_controller
- if isinstance(mnkInput, Button):
- return mouse_controller
- print(f'Could not find a controller that accepts {type(mnkInput)} input.')
- def simulate_press(mnkInput):
- print(f'Simulate {mnkInput} press')
- controller = get_controller(mnkInput)
- controller.press(mnkInput)
- def simulate_release(mnkInput):
- print(f'Simulate {mnkInput} release')
- controller = get_controller(mnkInput)
- controller.release(mnkInput)
- def simulate_tap(mnkInput, inputDelay = 50):
- simulate_press(mnkInput)
- sleep(inputDelay)
- simulate_release(mnkInput)
- sleep(inputDelay)
- ##### Main #####
- def main():
- if is_scrolllock_on():
- # Untoggle Scroll Lock (turn off LED).
- # Force the initial state of Scroll Lock to OFF when starting this script.
- simulate_tap(Key.scroll_lock)
- while True:
- for mnkInput,pressed in pressed_inputs.items():
- if pressed:
- # If pressed input is not the autofire button, or Scroll Lock is toggled (LED is on).
- if mnkInput != shoot_button or is_scrolllock_on():
- simulate_tap(mnkInput)
- else:
- # If capslock is released but still toggled (LED is on).
- if mnkInput == Key.caps_lock and is_capslock_on():
- # Untoggle Caps Lock (turn off LED).
- # Because i use Caps Lock for boost, i want the script to un-toggle the key when its not being held.
- simulate_tap(mnkInput)
- sleep(1)
- # WARNING: If you use an SCO FSD then uncomment this version of the main() function.
- # It changes Scroll Lock to act as a global on/off hotkey for the entire script.
- # With this version you will want to turn on Scroll Lock when using thrusters (to benefit from auto-boost),
- # and turn off Scroll Lock when in supercruise to avoid triggering supercruise-overdrive with a full-auto boost key.
- # def main():
- # if is_scrolllock_on():
- # # Untoggle Scroll Lock (turn off LED).
- # # Force the initial state of Scroll Lock to OFF when starting this script.
- # simulate_tap(Key.scroll_lock)
- # while True:
- # if is_scrolllock_on():
- # for mnkInput,pressed in pressed_inputs.items():
- # if pressed:
- # simulate_tap(mnkInput)
- # sleep(1)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement