A Python-based control system that uses MediaPipe and native gesture/key-handling libraries to translate hand gestures into in-game actions for Asphalt 8/9. It detects gestures like fist closures and hand orientations to simulate keyboard inputs for steering and actions like drifting or nitro.
All files are in the same folder:
main.pygesture_utils.cppkeyhandler.cpp- Compiled libraries (see Build Instructions):
- Windows:
keyhandler.dll,gesture_utils.dll - macOS/Linux:
libkeyhandler.dylib/libkeyhandler.so,libgesture_utils.dylib/libgesture_utils.so
- Windows:
requirements.txt
-
Python 3.7+
-
C++ compiler:
- Windows: MinGW-w64 or Visual Studio (MSVC)
- macOS/Linux:
g++(with-fPICsupport on Linux)
-
Python packages (see
requirements.txt):opencv-python mediapipe pyautogui
-
Open a terminal (e.g., PowerShell, Command Prompt with MinGW on PATH, or “Developer Cmd Prompt for VS”).
-
Compile keyhandler:
# Using MinGW: g++ -std=c++17 -shared -o keyhandler.dll keyhandler.cpp -Wl,--out-implib,libkeyhandler.aor, with MSVC (Developer Cmd Prompt):
cl /LD keyhandler.cpp /Fe:keyhandler.dll
-
Compile gesture_utils:
# Using MinGW: g++ -std=c++17 -shared -o gesture_utils.dll gesture_utils.cpp -Wl,--out-implib,libgesture_utils.aor, with MSVC:
cl /LD gesture_utils.cpp /Fe:gesture_utils.dll
-
Ensure
keyhandler.dllandgesture_utils.dllare in the same folder asmain.py.
-
Open a terminal.
-
Install Xcode Command Line Tools (macOS) or ensure
g++is installed (Linux). -
Compile keyhandler:
-
macOS:
g++ -dynamiclib -o libkeyhandler.dylib keyhandler.cpp \ -framework CoreFoundation -framework CoreGraphics -
Linux:
g++ -std=c++17 -fPIC -shared -o libkeyhandler.so keyhandler.cpp -ldl -lpthread
-
-
Compile gesture_utils:
-
macOS:
g++ -std=c++17 -shared -o libgesture_utils.dylib gesture_utils.cpp
-
Linux:
g++ -std=c++17 -fPIC -shared -o libgesture_utils.so gesture_utils.cpp
-
-
Rename or symlink libraries so that
main.pycan find them:-
macOS:
mv libkeyhandler.dylib keyhandler.dll mv libgesture_utils.dylib gesture_utils.dll
-
Linux:
mv libkeyhandler.so keyhandler.dll mv libgesture_utils.so gesture_utils.dll
-
-
Place
keyhandler.dllandgesture_utils.dllnext tomain.py.
-
Create a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Confirm your webcam is connected.
-
Run the script:
python main.py
-
Controls detected:
-
Right hand closed (fist) → press Space
-
Left hand closed (fist) → press Down arrow
-
Both hands:
- Measure slope between wrist points.
- Positive slope → hold Right arrow; negative slope → hold Left arrow.
-
-
Exit: When the cursor (index fingertip) of any hand moves into the top-left corner of the frame (within 10% width and height), the script automatically terminates.
- Adjust
FRAME_W,FRAME_H,TURN_COOLDOWNandFPSinmain.pyas needed. - On Linux, you might need to install
libgl1-mesa-glxor equivalent for OpenCV video capture. - Tested on macOS Sequoia 15.4.1