无意中看到按键精灵出Android版了,想了解一下,所以加入了内测,
由于脚本语法和VB差不多,所以上手很快,写了个天天爱消除的脚本来练习一下,
很早就知道按键精灵了,但一直没写过其脚本,这个算是我的第一个按键精灵脚本吧!
/****测试手机 小米1S分辨率 480*854游戏方格 68*68起始点 3,223**/Dim baseX,baseY,boxW,boxHDim I,X,Y,maxX,maxY,ret,Box(8, 8)baseX = 3baseY = 223boxW = 68boxH = 67.5maxX = 7maxY = 7ret = 0KeepScreen(true)TracePrint "开始消除。。。"'还没加入判断开始与结束的条件,使用时手工点停止For I = 1 To 200 'TracePrint I Call ReadBox() For Y = 1 To maxY For X = 1 To maxX ret = CheckMove(X, Y, maxX, maxY) Select Case ret Case 1 '上移 Tap baseX+(X-1)*boxW+30,baseY+(Y-1)*boxH+30 Tap baseX+(X-1)*boxW+30,baseY+(Y-2)*boxH+30 Case 2 '右移 Tap baseX+(X-1)*boxW+30,baseY+(Y-1)*boxH+30 Tap baseX+X*boxW+30,baseY+(Y-1)*boxH+30 Case 3 '下移 Tap baseX+(X-1)*boxW+30,baseY+(Y-1)*boxH+30 Tap baseX+(X-1)*boxW+30,baseY+(Y)*boxH+30 Case 4 '左移 Tap baseX+(X-1)*boxW+30,baseY+(Y-1)*boxH+30 Tap baseX+(X-2)*boxW+30,baseY+(Y-1)*boxH+30 End Select Next NextNextTracePrint "消除结束!!!"KeepScreen(false)EndScript'确定方块往哪个方向移动(返回:0-无,1-上,2-右,3-下,4-左)Function CheckMove(x, y, maxX, maxY) Dim ret ret = 0 '往上移 If ret=0 And y>1 Then If x>2 And BoxMatch(x-2,y-1, x-1,y-1, x,y) Then ret = 1 End If If x>1 And x<maxX And BoxMatch(x-1,y-1, x,y, x+1,y-1) Then ret = 1 End If If x<maxX-1 And BoxMatch(x,y, x+1,y-1, x+2,y-1) Then ret = 1 End If If y>3 And BoxMatch(x,y-3, x,y-2, x,y) Then ret = 1 End If End If '往右移 If ret=0 And x<maxX Then If y>2 And BoxMatch(x+1,y-2, x+1,y-1, x,y) Then ret = 2 End If If y>1 And y<maxY And BoxMatch(x+1,y-1, x,y, x+1,y+1) Then ret = 2 End If If y<maxY-1 And BoxMatch(x,y, x+1,y+1, x+1,y+2) Then ret = 2 End If If x<maxX-2 And BoxMatch(x,y, x+2,y, x+3,y) Then ret = 2 End If End If '往下移 If ret=0 And y<maxY Then If x>2 And BoxMatch(x-2,y+1, x-1,y+1, x,y) Then ret = 3 End If If x>1 And x<maxX And BoxMatch(x-1,y+1, x,y, x+1,y+1) Then ret = 3 End If If x<maxX-1 And BoxMatch(x,y, x+1,y+1, x+2,y+1) Then ret = 3 End If If y<maxY-2 And BoxMatch(x,y, x,y+2, x,y+3) Then ret = 3 End If End If '往左移 If ret=0 And x>1 Then If y>2 And BoxMatch(x-1,y-2, x-1,y-1, x,y) Then ret = 4 End If If y>1 And y<maxY And BoxMatch(x-1,y-1, x,y, x-1,y+1) Then ret = 4 End If If y<maxY-1 And BoxMatch(x,y, x-1,y+1, x-1,y+2) Then ret = 4 End If If x>3 And BoxMatch(x-3,y, x-1,y, x,y) Then ret = 4 End If End If CheckMove = retEnd Function'判断三个方块能否连线Function BoxMatch(x1, y1, x2, y2, x3, y3) Dim b1, b2, b3 b1 = Box(x1, y1) b2 = Box(x2, y2) b3 = Box(x3, y3) If BoxEquals(b1, b2) And BoxEquals(b1, b3) Then BoxMatch = True Else BoxMatch = False End IfEnd Function'判断两个方块是否一样Function BoxEquals(box1, box2) If ColorDiff(box1,box2)<50 Then BoxEquals = True Else BoxEquals = False End IfEnd Function'读入方块布局Sub ReadBox() KeepCapture Dim X,Y For Y = 1 To maxY For X = 1 To maxX Box(X,Y)=GetPixelColor(baseX+(X-1)*boxW+30, baseY+(Y-1)*boxH+30) Next Next ReleaseCaptureEnd Sub