Creating a King of Glory Gold‑Farming Script Using Python and ADB
This guide explains how to build a Python‑based ADB script that automates taps at specific screen coordinates to repeatedly farm gold in the mobile game King of Glory, covering environment setup, common ADB errors, coordinate extraction, full source code, and packaging as an executable.
The author wants to write a helper script (or cheat) for the mobile game King of Glory to automatically farm gold.
Principle
The script simulates taps at specific screen coordinates at specific times, bypassing manual gameplay.
Environment Setup
ADB Tool
Download ADB from https://adbshell.com/downloads/ and install; ensure the device appears.
Python and IDE (optional)
Install Python and an IDE; configuration steps omitted.
Gold Farming Steps
1. Connect phone via USB and enable developer mode.
2. Start ADB.
Error 1: Port 5037 occupied
netstat -ano | findstr "5037"
taskkill /pid <process_id> /fError 2: Missing DLL or developer mode not enabled
# copy adb.exe and AdbWinApi.dll to C:\WINDOWS\System32
# then copy them to C:\Windows\SysWOW643. Launch King of Glory, capture screenshots to obtain pixel coordinates.
Examples of coordinates: (1755,793) for 万象天工, (211,275), (1231,557), (1393,475), (1677,675), (1791,939), etc.
4. Script code
# -*- coding: utf-8 -*-
# @Author : daruida
# @Time : 2021/1/8 15:38
import os
from time import sleep
def click_screen(x, y):
os.system('adb shell input tap {} {}'.format(x, y))
def repeat(zidong):
print('开始挑战')
# 闯关
click_screen(1697, 861)
sleep(10)
# 跳过
print('点击跳过')
click_screen(2175, 45)
sleep(1)
# 自动
if zidong == 0:
print('点击自动')
click_screen(2117, 39)
zidong = 1
# 打完
sleep(60)
print('打完了')
# 跳过
click_screen(2175, 45)
sleep(10)
# 挑战完成
print('挑战完成\n\n')
click_screen(1000, 500)
sleep(1)
# 再次挑战
print('再次挑战\n\n')
click_screen(2001, 1011)
sleep(1)
repeat(zidong)
if __name__ == '__main__':
zidong = 0
print('刷金币初始化....')
click_screen(1755, 793) # 万象天宫
sleep(1)
click_screen(211, 275) # 冒险玩法
sleep(1)
click_screen(1231, 557) # 挑战
sleep(2)
print('通天塔')
click_screen(1393, 475) # 通天塔
sleep(1)
click_screen(1677, 675) # 大师级别
sleep(1)
click_screen(1791, 939) # 下一步
print('刷金币重复阶段...')
repeat(zidong)The script can be packaged into an executable with pyinstaller -F script.py and run after connecting the phone.
Testing
With a typical hero combination, the script can earn over 1000 gold per hour.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.