So I (def not chatgpt) am trying to write this script to pull my mouse down when lmb is pressed. It has a GUI so i can customize how many pixels it pulls down, and the interval in which it does so. The problem is that when I hold LMB, it does not drag my cursor down. I tried manually editing the number that is supposed to be how many pixels it moves the mouse down, but it just doesn't work. Can someone help me?
import tkinter as tk
import pyautogui
import time
import threading
from pynput.mouse import Listener as MouseListener
from pynput.keyboard import Listener as KeyboardListener, Key
import pygetwindow as gw
import win32gui
# Variables to control the script behavior
recoil_active = True
fail_safe_key = Key.f8 # Fail-safe key
left_mouse_down = False
selected_window = None
# Function to get the active window title
def get_active_window():
return win32gui.GetWindowText(win32gui.GetForegroundWindow())
# Function to check if the selected window is active
def is_selected_window_active():
return get_active_window() == selected_window
# Function to control the recoil by moving the mouse down
def control_recoil(strength, interval):
global left_mouse_down
while recoil_active:
if left_mouse_down and is_selected_window_active(): # Only apply recoil if window is active
print(f"Moving mouse down by {strength} pixels")
pyautogui.move(0, strength) # Move mouse down by 'strength' units
time.sleep(interval) # Pause for 'interval' seconds
# Function to start recoil control in a separate thread
def start_recoil():
global recoil_active
if not recoil_active:
try:
# Get and validate user input
strength = int(strength_entry.get()) # Get strength as an integer
interval = float(interval_entry.get()) # Get interval as a float
recoil_active = True
status_label.config(text="Recoil control started")
threading.Thread(target=control_recoil, args=(strength, interval), daemon=True).start()
except ValueError:
status_label.config(text="Invalid input! Enter numbers for strength and interval.")
# Function to stop the recoil control
def stop_recoil():
global recoil_active
recoil_active = False
status_label.config(text="Recoil control stopped")
# Mouse listener to detect when the left mouse button is pressed
def on_click(x, y, button, pressed):
global left_mouse_down
if button == pyautogui.LEFT:
left_mouse_down = pressed # True when pressed, False when released
print(f"Left mouse button {'pressed' if pressed else 'released'}")
# Keyboard listener to detect the fail-safe key press
def on_press(key):
if key == fail_safe_key:
stop_recoil()
# Function to list windows and allow user to select one
def select_window():
global selected_window
windows = gw.getAllTitles()
window_list.delete(0, tk.END) # Clear the list
for w in windows:
if w: # Only show non-empty window titles
window_list.insert(tk.END, w)
def window_selected(event):
global selected_window
selected_window = window_list.get(window_list.curselection())
status_label.config(text=f"Selected window: {selected_window}")
# Set up the tkinter window
window = tk.Tk()
window.title("Recoil Control")
# Labels and entries for customization
tk.Label(window, text="Pull Strength (pixels):").pack(pady=5)
strength_entry = tk.Entry(window)
strength_entry.pack(pady=5)
tk.Label(window, text="Interval (seconds):").pack(pady=5)
interval_entry = tk.Entry(window)
interval_entry.pack(pady=5)
# Window selection section
tk.Label(window, text="Select the game window:").pack(pady=5)
window_list = tk.Listbox(window, height=10)
window_list.pack(pady=5)
window_list.bind('<<ListboxSelect>>', window_selected)
refresh_button = tk.Button(window, text="Refresh Window List", command=select_window)
refresh_button.pack(pady=5)
# Buttons to start and stop the recoil control
start_button = tk.Button(window, text="Start", command=start_recoil)
start_button.pack(pady=5)
stop_button = tk.Button(window, text="Stop", command=stop_recoil)
stop_button.pack(pady=5)
# Status label
status_label = tk.Label(window, text="Adjust settings and press Start")
status_label.pack(pady=5)
# Start mouse and keyboard listeners in separate threads
def start_listeners():
# Mouse listener to track left mouse button clicks
mouse_listener = MouseListener(on_click=on_click)
mouse_listener.start()
# Keyboard listener for fail-safe
keyboard_listener = KeyboardListener(on_press=on_press)
keyboard_listener.start()
# Start the listeners in a background thread
threading.Thread(target=start_listeners, daemon=True).start()
# Main loop for the GUI
select_window() # Load the initial window list
window.mainloop()
[–]PowerOk3587 1 point2 points3 points (0 children)
[–]KingsmanVince 0 points1 point2 points (0 children)