我想用Python写一个游戏脚本,自动点击排队!

我刚学Python,用已掌握的知识已经用"autopy"的功能写了一个鼠标自动点击排队的脚本,但是我想让这个脚本不用在窗口最前端显示也能运行,就是最小化了也能继续在后台继续工作,可是不了解Python的强大功能,下面是代码,有些是在网上找的方法,大部分是我自己瞎琢磨的,求大神指点!
import win32gui
import win32con
import time
import math
import autopy

Left_btn=autopy.mouse.Button.LEFT #声明鼠标左键

colour_1 = (228,225,223) #RGB主界面
colour_2 = (229,197,141) #RGB准备
colour_3 = (44,24,19) #RGB战斗结束
colour_4 = (115,75,40)

def Ready(X_axis,Y_axis): ###取得所需要像素的R,G,B###

R = autopy.screen.get_color(X_axis,Y_axis)[0]
G = autopy.screen.get_color(X_axis,Y_axis)[1]
B = autopy.screen.get_color(X_axis,Y_axis)[2]
return R,G,B

class GameAssist:

def __init__(self,wdname):

    """初始化"""


    #取得游戏窗口句柄

    self.hwnd = win32gui.FindWindow(0,wdname)

    if not self.hwnd:
        print("未找到游戏窗口,请确认窗口句柄名称:【%s】"% wdname)

        exit()

    #窗口显示在最前面
    win32gui.SetForegroundWindow(self.hwnd)

    newx = 0
    newy = 1
    win32gui.SetWindowPos(self.hwnd,
                            win32con.HWND_TOPMOST,
                            newx,
                            newy,
                            300,
                            300,
                            win32con.SWP_SHOWWINDOW)

def Line_Up():
#日和坊自动排队

time.sleep(1)
autopy.mouse.move(102,262)
time.sleep(0.5)
autopy.mouse.click()
time.sleep(1)
autopy.mouse.move(102,262)
time.sleep(0.5)
autopy.mouse.click()
time.sleep(0.5)
autopy.mouse.move(183,240)
time.sleep(0.5)
autopy.mouse.toggle(Left_btn,True)
time.sleep(0.5)
autopy.mouse.smooth_move(183,155)
time.sleep(0.5)
autopy.mouse.toggle(Left_btn,False)
time.sleep(0.5)
autopy.mouse.move(183,256)
time.sleep(0.5)
autopy.mouse.click()
time.sleep(0.5)
autopy.mouse.move(288,280)
time.sleep(0.5)
autopy.mouse.click()

def Tricks(): ####鼠标模拟点击####

while True:

    if Ready(100,258) == colour_1:   #对比主界面RGB是否为真

        Line_Up()  #日和坊自动排队
        time.sleep(4)


        while Ready(130,248) != colour_4:

            Line_Up()

不在前端也能运行就不能用模拟鼠标点击,而是应该发鼠标/键盘消息,用sendmessage
一些游戏软件有反外挂的措施会导致发消息无效,一般的程序是没关系的。
你可以google下