chatgpt-4o-latest-20250326· OpenAI
LMArena Human Preference 140K
Write a python script that moves mouse down right, then down left, then upleft, then up…
- User
Write a python script that moves mouse down right, then down left, then upleft, then up right, so it is back to starting position.
- Assistant
Of course! Here's a Python script that moves the mouse in the pattern you described:
import pyautogui import time # Set the distance to move in each direction distance = 100 # pixels duration = 0.5 # seconds for each move # Give user time to move mouse to starting position print("Starting in 3 seconds. Move your mouse to the starting position.") time.sleep(3) # Move down-right pyautogui.moveRel(distance, distance, duration=duration) # Move down-left pyautogui.moveRel(-distance, distance, duration=duration) # Move up-left pyautogui.moveRel(-distance, -distance, duration=duration) # Move up-right pyautogui.moveRel(distance, -distance, duration=duration) print("Done!")
✅ Explanation:
pyautogui.moveRel(x, y, duration)moves the mouse relative to its current position.- Positive
xmoves right, positiveymoves down. - Negative
xmoves left, negativeymoves up. - The script moves:
- Down and right
- Down and left
- Up and left
- Up and right
- Ending back at the starting point.
Requirements:
Install
pyautoguiif you haven't already:pip install pyautogui
⚠️ Warning: Be careful when automating mouse movements, especially if you run scripts that move the mouse indefinitely. Always have a way to interrupt (e.g., move mouse to a corner to trigger
pyautogui.FAILSAFE).
Would you also like a version that draws a smooth square or diamond shape instead of just straight lines? 🎨
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.