vmware天下client自动重登

AutoHotKey v1.x

; 配置文件路径
configFile := A_ScriptDir "\auto_login.ini"

; 检查配置文件是否存在
if not FileExist(configFile) {
    ; 创建默认配置文件内容
	defaultConfig =
	defaultConfig .= "# 天下游戏:开机和掉线自动登录配置文件`n"
	defaultConfig .= "`n"
	defaultConfig .= "# 游戏路径`n"
	defaultConfig .= "tx_dir=C:\Documents and Settings\Administrator\桌面\Tianxia`n"
	defaultConfig .= "`n"
	defaultConfig .= "# 游戏主程序,一个机子只开一个的用!`n"
	defaultConfig .= "tx_list=tx.exe tx-new.exe tx-new1.exe tx-new2.exe tx-new3.exe`n"
	defaultConfig .= "`n"
	defaultConfig .= "# 客户端进程`n"
	defaultConfig .= "client=client.exe`n"
	defaultConfig .= "`n"
	defaultConfig .= "# 用户账号`n"
	defaultConfig .= "account=test3276243`n"
	defaultConfig .= "`n"
	defaultConfig .= "# 用户密码`n"
	defaultConfig .= "password=test3276243`n"
	; 写入文件
    FileAppend, %defaultConfig%, %configFile%
}

; 读取配置文件
config := Object()
Loop, Read, %configFile%
{
    line := A_LoopReadLine
    If RegExMatch(line, "^(.*)=(.*)$", match) {
	    StringSplit, groups, match, "="
        key := groups1
        value := groups2
        config[key] := value
		;MsgBox, % "第" A_LineNumber "行:" key " = "value
    }
}

;MsgBox, % "第" A_LineNumber "行:" "config.size = " ObjCount(config)

; 提取配置
txDir := config.tx_dir
txList := StrSplit(config.tx_list, " ")
clientExe := config.client
account := config.account
password := config.password

;MsgBox, % "第" A_LineNumber "行:" "config.tx_list = " config.tx_list
;MsgBox, % "第" A_LineNumber "行:" "txList = " ObjCount(txList)
;MsgBox, % "第" A_LineNumber "行:" "txList = " txList[1]

; 定义检查进程和启动进程的函数
checkProcess(name) {
    Process, Exist, %name%
    return ErrorLevel
}
startProcess(path) {
    Run, %path%
}

; 点击窗口中指定位置
ClickWindow(winTitle, x, y) {
    CoordMode, Mouse, Window
    IfWinExist, %winTitle% 
	{
        WinActivate, %winTitle%
        Sleep, 500
        Click, %x%, %y%
    }
}

; 主逻辑循环
Loop {
    ; 检查 tx_list 中的每个进程
    txExists := false
    txName := ""
    For index, tx in txList {
        If checkProcess(tx) {
            txExists := true
            txName := tx
			MsgBox, % "第" A_LineNumber "行:" "txExists = " tx "(" txExists ")"
            break
        }
    }
	
	If !txExists{
        ; 结束 client.exe 进程
        Process, Close, %clientExe%

        ; 启动 client.exe
        startProcess(txDir "\" clientExe)

        ; 等待 client.exe 进程加载
        While !checkProcess(clientExe)
            Sleep, 500

        ; 等待 client 窗口出现
        WinWaitActive, ahk_exe %clientExe%
		
		; 点击 client 窗口左上角坐标
        ClickWindow("ahk_exe " clientExe, 55, 65)

        ; 等待 tx 进程启动 (不使用 ArrayAny)
        txProcessFound := false
        While !txProcessFound {
            For index, tx in txList {
                If checkProcess(tx) {
                    WinWaitActive, ahk_exe %tx%
                    break
                }
            }
            Sleep, 500
        }
		
		sleep, 5000
		; 替代鼠标点击关闭窗口
		ControlSend,, !{F4}, ahk_exe %tx%
		
		; 点击登录位置
        ClickWindow("ahk_exe " tx, 440, 300)

        ; 点击用户名位置
        ClickWindow("ahk_exe " tx, 440, 270)
	}
    Sleep, 5000 ; 循环间隔
}