VBA解决Windows空当接龙的617局
Windows的自带游戏空当接龙,其中第617局是比较难解的,需要尝试的次数比较多,而且经常忘记解法和步骤。
原本希望使用AutoIt或AutoHotkey、AAuto一类的工具,写一段自动化脚本快速解决这一局,但这些工具需要安装,而且容易被当做病毒。通过Office中的VBA调用Windows的API,对游戏窗口发送按键消息,可以快速演示解法。
DeclareFunctionFindWindowLib"user32"Alias_
"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLong
DeclareFunctionSendMessageLib"user32"Alias_
"SendMessageA"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLong
ConstWM_CHAR=&H102
Subf()
s="8380838180"&_
"202772"&_
"4846414842"&_
"8948707478074027"&_
"101400410011619"&_
"20002422120"&_
"3234243242343038"&_
"585363575650"&_
"1010131535131218"
h=FindWindow("FreeWClass","空当接龙游戏#617")
Fori=1ToLen(s)
c=Mid(s,i,1)
m=0.1
Ifc>="0"Andc<="9"Then
a=SendMessage(h,WM_CHAR,Asc(c),0)
Else
m=0.3
EndIf
m=m+Timer:DoWhileTimer<m:DoEvents:Loop
Next
EndSub