Control Asphalt 8 with hand gestures using your webcam! This Python application uses computer vision to detect hand movements and translates them into keyboard inputs for steering, nitro, and reverse controls.
- Hand Steering: Turn your hands left or right to steer the car
- Nitro Control: Raise your index finger to activate nitro boost
- Reverse Control: Raise your pinky finger to reverse
- Real-time Visual Feedback: See your steering angle and controls on screen
- Smooth Controls: Advanced smoothing and deadzone handling for precise steering
- Flexible Architecture: Easily adapt the script to other games by modifying the
KeyHandlerclass without touching the main code
- Python 3.7+
- Windows/macOS/Linux
- Webcam
- Asphalt 8 (PC version)
pip install opencv-python
pip install mediapipe
pip install numpy
pip install pynputOr install all dependencies at once:
pip install -r requirements.txt-
Clone the repository
git clone https://github.com/yourusername/asphalt8-hand-steering.git cd asphalt8-hand-steering -
Install dependencies
pip install -r requirements.txt
-
Optional: Add steering wheel image
- Place a steering wheel image named
steering.pngin thehand-steeringfolder - The script will create a default steering wheel if no image is found
- Place a steering wheel image named
-
Start Asphalt 8
- Launch Asphalt 8 on your PC
- Set the game to windowed mode for best results
- Make sure the game window is focused
-
Run the script
python hand_steering.py
-
Position yourself
- Sit in front of your webcam
- Make sure your hands are visible in the camera frame
- The script works best with good lighting
-
Control the game
- Steering: Rotate both hands left or right (like holding a steering wheel)
- Nitro: Point your index finger up
- Reverse: Point your pinky finger up
- Quit: Press ESC to exit
| Gesture | Action | Key Binding |
|---|---|---|
| Hands rotated left | Steer left | Left Arrow |
| Hands rotated right | Steer right | Right Arrow |
| Index finger up | Nitro boost | Spacebar |
| Pinky finger up | Reverse | Down Arrow |
You can adjust various parameters in the KeyHandler class:
# Steering sensitivity
self.STEERING_LIMIT = 50.0 # Maximum rotation angle (degrees)
self.DEADZONE = 8.0 # Deadzone to ignore small movements
self.BASE_TAP_INTERVAL = 0.20 # Base interval between key taps
self.MIN_TAP_INTERVAL = 0.05 # Minimum interval for rapid steering
self.SMOOTHING_FACTOR = 0.2 # Smoothing factor (0-1)Note: Thanks to this class-based architecture, you can adapt the script to other games by only changing the key mapping inside
KeyHandler. No modifications to the main game loop or detection logic are needed. This is a practical example of UML modeling benefits, where clear separation of concerns allows for flexible and maintainable code.
-
"No module named 'cv2'"
- Solution:
pip install opencv-python
- Solution:
-
"Permission denied" errors on macOS/Linux
- Solution: Run with
sudoor check accessibility permissions
- Solution: Run with
-
Hand detection not working
- Ensure good lighting
- Keep hands visible in the camera frame
- Try adjusting detection confidence in the
Steeringclass
-
Game not responding to controls
- Make sure Asphalt 8 window is focused
- Try running the script as administrator
- Check if your game uses different key bindings
- Change camera index: Modify
cv2.VideoCapture(0)tocv2.VideoCapture(1)for external cameras - Adjust resolution: The script sets camera to 320x180 for better performance
- Camera not found: Make sure no other applications are using the camera
- Lighting: Use good lighting for better hand detection
- Background: Plain backgrounds work better than cluttered ones
- Distance: Sit about 2-3 feet from the camera
- Hand Position: Keep both hands visible and parallel to the camera
- Calibration: Practice the gestures before starting a race
- Uses MediaPipe for real-time hand landmark detection
- Tracks 21 key points on each hand
- Calculates steering angle using geometric relationships
- Implements smooth steering with exponential moving average
- Uses angle-based tap intervals for responsive steering
- Separate threads for key press/release timing
- Deadzone handling: Prevents unwanted inputs from small movements
- Direction smoothing: Reduces jitter in steering
- Adaptive timing: Faster tapping for sharper turns
asphalt8-hand-steering/
โ
โโโ hand_steering.py # Main script
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
โโโ hand-steering/
โ โโโ steering.png # Optional steering wheel image
โโโ demo.gif # Demo video (optional)
Hereโs a simplified UML diagram of the script highlighting the key components:
+----------------+
| Steering |
+----------------+
| - mp_hands |
| - hands |
| - mp_drawing |
+----------------+
| + detect()
| + getRotation()
| + getGearAceleration()
| + overlay_rotated_circle()
| + signed_angle_3pts(A, B, C)
| + close()
+----------------+
^
|
v
+----------------+
| KeyHandler |
+----------------+
| - keyboard: Controller
| - active_keys: set
| - STEERING_LIMIT
| - DEADZONE
| - BASE_TAP_INTERVAL
| - MIN_TAP_INTERVAL
| - TAP_DURATION
| - SMOOTHING_FACTOR
| - filtered_angle
| - current_direction
| - last_tap_time
+----------------+
| + send_steering(raw_angle)
| + send_reverse(active=True)
| + send_nitro(active=True)
| + _press_key(key)
| + _release_key(key)
| + _release_all_steering_keys()
| + _smooth_angle(new_angle)
| + _get_tap_interval(angle)
| + _tap_key(key)
+----------------+
^
|
v
+----------------------+
| Main Loop |
+----------------------+
| - cap: VideoCapture |
| - detector: Steering |
| - key_handler: KeyHandler
| - circle_img |
+----------------------+
| + capture_frame()
| + detect_hands()
| + compute_rotation()
| + send_commands()
| + display_frame()
+----------------------+
Benefit: The UML highlights how detection and key control are separated, making it easy to modify key bindings for any game without touching the detection logic.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This project is for educational and entertainment purposes only. Use responsibly and ensure compliance with game terms of service.
If you encounter any issues or have questions:
-
Check the troubleshooting section
-
Open an issue on GitHub
-
Include:
- Your operating system
- Python version
- Error messages (if any)
- Camera specifications
Enjoy racing with your hands! ๐