使用软件:AHK v1.1.34,killhandle
期望实现的效果
1.自动杀DiabloII Check For Other Instances进程
2.自动登陆战网battle.net客户端,输入用户名密码,登陆,(登陆的蓝色按钮需要截图保存在同位置下,文件名login.bmp,图片样子见文章末尾)
3.自动点击进入游戏(识别login.bmp),到人物选择界面(需要截图右下角的删除按钮,保存为loading.bmp,图片样子见文章末尾),结束
4.实现双开,多开
使用说明:
a.需要在微软下载killhandle64.exe,本代码使用的是killhadle64.exe,根据系统不同可能要选择killhadle.exe,需要修改代码中的killhandle版本。未测试。
b.需要把handle64.exe复制到C:\Windows\SysWOW64 和 C:\Windows\System32文件夹下,否则会报找不到位置,可能跟AHK是32 还是64有关。
c.需要在前3行配置用户名,密码和游戏路径
d.以上可实现单开
e.多开就将代码1对应的AHK文件复制多个,修改前3行配置。然后新建个AHK文件调用前面复制的文件就行。调用的代码见代码2:
纯新手,代码比较冗余,高手请略过。
会不会导致封号,未知。慎用。
代码1:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;config;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ID=
PSW=
dir=D:\diabloR\Diablo II Resurrected\Diablo II Resurrected Launcher.exe
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;config;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MsgBox, 0, 杀进程, 杀!杀!杀! 此弹窗2秒后关闭, 2
;需要把handle64.exe复制到C:\Windows\SysWOW64 和 C:\Windows\System32文件夹,否则会报找不到位置,可能跟AHK是32 还是64有关。
shell := ComObjCreate("WScript.Shell")
; 通过 cmd.exe 执行单条命令
pth :="C:\Windows\System32\handle64.exe "
exec := shell.Exec(pth "-a -p D2R.exe Instances")
; 读取并返回命令的输出
sleep 2000
strText :=exec.StdOut.ReadAll()
s :=strsplit(strText, chr(10))
x :=s.MaxIndex()
for index, element in s
{
stxt :=s[A_Index]
ss :=strsplit(stxt,": ")
if ss.Length() >1
{
{
sstxtA :=ss[2]
sstxtB :=ss[3]
x :=InStr(sstxtA, " ") - 1
strINGleft,D2rPID,sstxtA,x ;获取D2R程序PID
stringright,handle,sstxtB,4 ;获取DiabloII Check For Other Instances的handle
cmdt := " handle64.exe -c " handle " -p " D2rPID " -y"
ComObjCreate("Shell.Application").ShellExecute( "cmd.exe"," /c " cmdt,"","runas",1) ;杀进程
}
}
}
;以上杀进程
;RunWaitOne("killhandle.vbs " A_ScriptDir)
sleep,2000
run,%dir%
Sleep, 1000
winex.wait("battle.net")
winex.findActivate("battle.net")
count :=1
while (count<100)
{
imageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, login.bmp
if ErrorLevel = 2
{
MsgBox 没有图片文件
count :=99
}
else if ErrorLevel = 1
{
MsgBox, 0, 准备登陆, 找不到登陆按钮,找到后则输入用户名密码 此弹窗2秒后关闭, 2
count++
Sleep, 5000
}
else
{
;MsgBox,找到
count :=999
;Sleep, 2000
}
count++
}
Sleep, 200
; MsgBox,窗口打开
send +{Tab}
Sleep, 200
send {Delete}
SendInput {TEXT}%ID%
Sleep, 200
send {enter}
Sleep, 200
send {tab}
SendInput {TEXT}%PSW%
Sleep, 200
click %FoundX%,%FoundY%
;输完用户名,找登陆按钮
;Sleep, 5000
;登陆后,找登陆图标
count :=1
while (count<999)
{
imageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, login.bmp
if ErrorLevel = 2
{
MsgBox 没有图片文件
count :=991
}
else if ErrorLevel = 1
{
MsgBox, 0, 准备进入游戏, 等待进入游戏按钮 此弹窗2秒后关闭, 2
count++
Sleep, 3000
}
else
{
click %FoundX%,%FoundY%
count :=9999
Sleep, 2000
}
count++
}
winex.wait("D2R.EXE")
winex.findActivate("D2R.EXE")
count :=1
while (count<999)
{
imageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, loading.bmp
if ErrorLevel = 2
{
MsgBox 没有图片文件
count :=991
}
else if ErrorLevel = 1
{
MsgBox, 0, 准备进入游戏, 等待连接界面 此弹窗2秒后关闭, 2
count++
Sleep, 1000
ControlSend ,,{SAPCE},D2R,,,
}
else
{
click %FoundX%,%FoundY%
count :=9999
Sleep, 1000
}
count++
}
MsgBox, 0, 成功,游戏已打开 此弹窗2秒后关闭, 2
ExitApp
代码2:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
runwait,1.AHK
runwait,2.AHK
;几开上面就增加几个,对应的就ahk文件也要复制几个。名称注意一致。
ExitApp


以上,有谁优化了代码,欢迎分享,谢谢!