This project provides a Python-based mouse recorder and player that captures mouse events (movements, clicks, and scrolls), stores them in a JSON file, and streams real-time touch data over UDP. It is designed for UI testing, automation, and input replay systems.
- β Mouse Event Recording (movement, click, scroll)
- π€ UDP Touch Data Streaming (normalized coordinates)
βΆοΈ Playback with Timing Accuracy- π Smooth Drag Prediction
- β±οΈ Adjustable Playback Speed
- π Emergency Stop Key Support
- πΎ JSON Output for Analysis/Replay
.
βββ recorder.py # Record mouse events and send UDP data
βββ player.py # Replay recorded mouse events
βββ mouse_track.json # Output file from recorder
βββ protocol.py # Defines TouchData for UDP packet structure
βββ protocol.py # To receive UDP messages sent via protocol.py
βββ README.md # Project documentation
- Python 3.7+
- pyautogui
- pynput
- keyboard
- numpy
pip install pyautogui pynput keyboard numpy
π Usage -ποΈ Record Mouse Events
python recorder.py
- Waits 3 seconds before starting.
- Records movements, clicks, scrolls.
- Sends live (x, y) over UDP if mouse is pressed.
- Press Scroll Lock or Ctrl+C to stop.
- Output saved to:
mouse_track.json
π¬ Play Back Events
python player.py
- Replays all recorded events.
- Uses original timing unless modified via SPEED_FACTOR.
- Supports drag prediction for smoother paths.
- Press Scroll Lock or
Ctrl+Cto stop at any time.
βοΈ Configuration Options
- You can customize in
recorder.pyandplayer.py:
Option Descriptions
RECORDING_DELAYDelay before starting recordingSPEED_FACTORPlayback speed multiplier (e.g., 2.0 = 2x)STOP_KEY Hotkeyto stop recording/playbackDRAG_PREDICTIONEnable smoother drag motionADDRESS UDPtarget address and portWIDTH/HEIGHTScreen resolution for coordinate scaling
π‘ UDP Streaming Format
- The TouchData class in
protocol.pyis used to: - Normalize coordinates (0β1 range)
- Package them into byte format
- Send via UDP to a target listener
You can customize this class to match your target application's protocol.
π§ͺ Example Use Cases
- Automated UI testing for desktop apps
- Creating reproducible input demos
- Remote control/input replay in custom environments
- Input stream generation for touch emulation
π οΈ Future Improvements
- Add support for keyboard event capture
- Include GUI for easier recording/playback
- Cross-platform enhancements for hotkey handling
π Acknowledgments
- Built using:
pyautogui
pynput
keyboard