I'm basically trying to make my own version of reWASD. I'm mapping controller input to keyboard presses, but the game detects the mouse when I move it around.
I tried to make it so that the cursor would constantly go to the same place, but that didn't work. Is there any way to just disable the window from detecting mouse input? This is my current code:
import vgamepad as vg
import time
import pyautogui
# Create a virtual DualShock 4 gamepad
gamepad = vg.VDS4Gamepad()
# Store the original mouse position
original_mouse_x, original_mouse_y = pyautogui.position()
# Function to map mouse position to joystick values
def map_mouse_to_joystick(mouse_x, mouse_y, screen_width, screen_height):
# Normalize mouse coordinates to [-1, 1]
normalized_x = (mouse_x / screen_width) * 2 - 1
normalized_y = (mouse_y / screen_height) * 2 - 1
# Clamp values to ensure they are within the valid range
joystick_x = max(min(normalized_x, 1), -1)
joystick_y = max(min(normalized_y, 1), -1)
return joystick_x, joystick_y
# Main loop to update joystick position based on mouse movement
def main():
# Assuming a screen resolution of 1920x1080 for this example
screen_width = 1920
screen_height = 1080
while True:
# Get current mouse position
mouse_x, mouse_y = pyautogui.position()
# Move the mouse cursor back to its original position
pyautogui.moveTo(original_mouse_x, original_mouse_y, duration=0)
# Map mouse position to joystick values
joystick_x, joystick_y = map_mouse_to_joystick(mouse_x, mouse_y, screen_width, screen_height)
# Update the right joystick position
gamepad.right_joystick_float(x_value_float=joystick_x, y_value_float=joystick_y)
gamepad.update()
# Run the main loop
if __name__ == "__main__":
main()