In this little project I tried to use Python and openCV template matching to play Whac-a-mole automatically while holding the Spacebar key.
If you want to try it, you will either need Python Poetry (package manager) or manually install needed packages:
- Python 3.11
- keyboard
- opencv-python-headless
- mss
- pyautogui
How to run with Poetry:
- Clone the repo
- Install Poetry
- Run
poetry install
from terminal while positioned in the project folder - Open Whac-a-mole
- Screenshot the part of image that you want to recognize (the mole in this example) that is always unchanged (example comparison_image.png included) and put it in
openCV_test/files
as comparison_image.png - Run start.bat from
openCV_test/
- Hold Spacebar to automatically click on the mole and rack up points
Press Page Up to see debug info in terminal, Page Down to turn it off.
To stop the script, use Ctrl+C or exit the terminal.