Skip to content

Instantly share code, notes, and snippets.

@deseven
Created July 7, 2023 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deseven/8cf32700382aac410c212180755dc903 to your computer and use it in GitHub Desktop.
Save deseven/8cf32700382aac410c212180755dc903 to your computer and use it in GitHub Desktop.
Very simple bot for Tap Ninja
# Very simple bot for Tap Ninja
# (https://store.steampowered.com/app/1891700/Tap_Ninja__Idle_game/)
# made by deseven, 2023
# The bot will perform building/tech upgrades every 30 seconds and
# ascention every 40 minutes (could be adjusted, see RUN_TIME below),
# very helpful for getting enough elixir on later stages of the game.
# Prerequisites:
# - Windows (should be easily portable to other OS)
# - Python 3.7 or higher
# - you should have "buy all" button unlocked in game
# - the game should be ran in windowed mode
# Instructions:
# 1. Install Python 3.7 or higher (I used 3.11).
# 2. Install pynput and pywin32 with pip.
# 3. Run the game and open the main toolbar.
# 4. Run the script either with IDLE or in command line.
# 5. To quit simply switch focus to any other window.
import sys
import time
from win32 import win32gui
from pynput import *
RUN_TIME = 2400
BUY_BUILDINGS = True
BUY_UPGRADES = True
ninja = win32gui.FindWindow(None, r'Tap Ninja')
if not ninja:
sys.exit('Tap Ninja window not found')
win32gui.SetForegroundWindow(ninja)
win32gui.MoveWindow(ninja,10,10,1280,720, True)
k = keyboard.Controller()
m = mouse.Controller()
buildingsTime = 0
upgradesTime = 0
startTime = 0
def DoKey(key):
k.press(key)
time.sleep(0.1)
k.release(key)
time.sleep(0.1)
def DoClick(x,y):
m.position = (x,y) # ascend button
time.sleep(0.1)
m.press(mouse.Button.left)
time.sleep(0.1)
m.release(mouse.Button.left)
time.sleep(0.1)
while True:
time.sleep(1.0)
currentTime = time.time()
#print(currentTime)
if win32gui.GetForegroundWindow() != ninja:
sys.exit('Game focus lost')
if RUN_TIME and (currentTime - startTime >= RUN_TIME):
print('Ascending...')
DoKey('3')
DoClick(1160,215) # ascend button
DoClick(1040,555) # ascend confirm button
startTime = currentTime
buildingsTime = 0
upgradesTime = 0
if BUY_BUILDINGS and (currentTime - buildingsTime >= 30):
print('Buying more buildings...')
DoKey('1')
for x in range(5):
DoClick(1195,700) # buy all button
time.sleep(1)
buildingsTime = currentTime
if BUY_UPGRADES and (currentTime - upgradesTime >= 30):
print('Buying more upgrades...')
DoKey('2')
for x in range(5):
DoClick(1160,215) # buy all button
time.sleep(1)
upgradesTime = currentTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment