按键5级认证考题

1、鼠标按圆型移动,半径为r=100,圆点为(200,200),请写出代码.
Dim a, x, y
MoveTo 100, 200
For a = 0 To 360
x = 200 - 100 * cos(a*3.14/180)
y = 200 - 100 * sin(a*3.14/180)
MoveTo x, y
Delay 5
Next
EndScript

1、(前台)区域范围为(100,150)到(200,300)内的所有点是否均为"FFFFFF",是则弹出对话框"没有其他颜色",否则弹出第一个点的颜色值并退出程序. 请写出代码
x = 100
y = 150
RtColor = Plugin.Color.GetPixelColor(x, y, 0)
RtColor1 = RtColor
While (y < 300)
x=100
While (x < 200)
If RtColor = "FFFFFF" Then
x = x + 1
Else
MessageBox RtColor1
ExitScript
End If
RtColor = Plugin.Color.GetPixelColor(x, y, 0)
Wend
y=y+1
Wend
MessageBox "没有其他颜色"

2、利用多线程对多个记事本的窗口位置进行随机移动.请写出代码
RunApp "notepad.exe" //启动3个记事本测试用
RunApp "notepad.exe"
RunApp "notepad.exe"
Delay 2000 //等待3个记事本工具打开
DimEnv Hwnd1
HwndEx = Plugin.Window.Search("记事本")
Hwnd = Split(HwndEx,"|")
If UBound(Hwnd) >= 0 Then //判断是否搜到句柄
For i = 0 To UBound(Hwnd) - 1
wnd = Clng(Hwnd(i)) //类型转换
Hwnd1 = wnd
BeginThread 移动 //启动线程
Delay 100 //启动线程需要点时间
Next
End If
Do
Delay 1000
Loop
Sub 移动
Hwnd2 = Hwnd1
Randomize
x = Int(Rnd * 500)
Randomize
y = Int(Rnd*500) //
MessageBox x&","&y
Call Plugin.Window.Move(Hwnd2, x+ 100, y + 100)
End Su

3、筛选出100以内所有个位数加十位数等于10的数,例如82,8+2=10满足条件,请写出代码
s=""
For i = 1 To 99
a = i mod 10
b = int(i / 10)
If (a + b) = 10 Then
s=s&i&"|"
End If
Next
MessageBox s

4、写一个算法可以将十进制的字符串转成八进制的字符串.例如"8"->"10",请写出代码
Public Function DEC_to_OCT(Dec)
DEC_to_OCT = ""
Do While Dec > 0
DEC_to_OCT = Dec Mod 8 & DEC_to_OCT
Dec = Dec \ 8
Loop
End Function
a=DEC_to_OCT("8") MessageBox a

5、有N个窗口,第一个窗口移动到(0,0)点,其余的窗口根据第一个窗口平铺,窗口不超出屏幕边缘(窗口平铺),请写出代码 RunApp "notepad.exe"
RunApp "notepad.exe"
RunApp "notepad.exe"
RunApp "notepad.exe"
RunApp "notepad.exe"
RunApp "notepad.exe"
HwndEx = Plugin.Window.Search("记事本")
Hwnd = Split(HwndEx, "|")
ScreenX = Plugin.Sys.GetScRX()
ScreenY = Plugin.Sys.GetScRY()
MessageBox ScreenX
sRect = Plugin.Window.GetWindowRect(Hwnd(0))
MessageBox sRect
xy = Split(sRect, "|")
x = xy(2) - xy(0)
y =

xy(3) - xy(1)
sx = 0
sy = 0
i=0
MessageBox x
While (Screeny-sy >y)
While (ScreenX - sx > x)
Delay 10
Call Plugin.Window.Move(Hwnd(i),Cstr(sx),Cstr(sy))
sx = sx + x
i = i + 1
If i > UBound(Hwnd)-1 Then
ExitScript
End If
Wend
sy = sy + y
sx=0
MessageBox sy
Wend

写一个子程序,可以使鼠标从当前的坐标逐点的移动到目的坐标(带轨迹的鼠标移动),请写出代码
Do
Call a(50, 50)
Call a(800, 600)
Loop

sub a(x,y)
Do
GetCursorPos x0, y0
If x > x0 Then
i = 1
ElseIf x < x0 Then
i = -1
ElseIf x = x0 Then
i = 0
End If

If y > y0 then
ii = 1
ElseIf y < y0 then
ii = -1
ElseIf y = y0 then
ii = 0
End If

MoveR i, ii

If x = x0 and y = y0 Then
Exit do
End If
Loop
End sub








11、随即生成一个1~100之间的整数,玩家可以通过inputbox输入数字,猜对则退出游戏,猜错则提示答案的范围(猜数游戏),请

写出代码
例如:
随机数为:60,用户输入20,程序提示"答案范围为:20~100".
用户再次输入75,程序提示"答案范围为:20~75".
用户再次输入60,程序提示"猜中",然后退出程序.


Randomize
答案 = int(Rnd * 100) + 1
最小数 = 1
最大数 = 100
数字 = InputBox("(猜数游戏),输入1~100之间的整数,玩家可以通过输入数字,猜对则退出游戏,猜错则提示答案的范围")
数字=int(数字)
Do
If 数字 = 答案 Then
MsgBox 数字 & ",恭喜答对了"
EndScript
ElseIf 数字 > 答案 Then
最大数 = 数字
ElseIf 数字 < 答案 Then
最小数 = 数字
End If
数字 = InputBox("答案范围为:" & 最小数 & "~" & 最大数)
数字 = int(数字)
Loop







12、鼠标按圆型移动,半径为r=100,圆点为(200,200),请写出代码.
圆点x = 200 : 圆点y = 200 : 半径 = 100 : 圆周率 = 3.14 : 角度数 = 1
//公式: 弧度 =角度*圆周率/180
Do
MoveTo 圆点x + 半径 * cos(角度数 * 圆周率 / 180), 圆点y + 半径 * Sin(角度数 * 圆周率 / 180)
角度数 = 角度数 + 1
Loop








13、锁定鼠标位置在(200,300)到(500,600)之间,超出范围则回到边界(鼠标范围锁定),请写出代码
Call 锁范围(200,300,500,600)

Function 锁范围(x1,y1,x2,y2)
Do
GetCursorPos x, y
If x < x1 or x > x2 or y < y1 or y > y2 Then
If x < x1 Then
x = x1
ElseIf x > x2 Then
x=x2
End If
If y < y1 Then
y = y1
ElseIf y > y2 Then
y=y2
End If
MoveTo x, y
End If

Loop
End Function









?可以让普通窗口(例如记事本)在屏幕内移动,碰到屏幕边缘随机反向移动(类似屏幕保护的汽泡程序),请写出
Call 泡泡屏保("记事本")

Function 泡泡屏保(模糊标题)
Hwnd = Split(Plugin.Window.Search(模糊标题), "|")
If UBound(Hwnd)>=0 = 0 Then
EndScript
End If
iii = 3
i = iii : ii = iii
最大宽 = Plugin.Sys.GetScRX():最大高 = Plugin.Sys.GetScRY()
边框 = Split(Plugin.Window.GetWindowRect(Hwnd(0)), "|")
W1 = Clng(边框(0)) : H1 = Clng(边框(1)) : W2 = Clng(边框(2)) : H2 = Clng(边框(3))
W0 = W2 - W1 : H0 = H2 - H1
do
If W1 <= 0 Then
i = 1 * iii
ElseIf W1 + W0 >= 最大宽 Then
i = -1 * iii
End If
If H1 <= 0 Then
ii = 1 * iii
ElseIf H1 + H0 >= 最大高 Then
ii = -1 * iii
End If
W1 = W1 + i : H1 = H1 + ii
Call Plugin.Window.Move(Hwnd(0), W1, H1 )
Delay 50
Loop
End Function


15、获取数组array(10,9,1,5,2,3,4,5,6,11)中最接近平均数的值,请写出代码
a = array(10, 9, 1, 5, 2, 3, 4, 5, 6, 11)
i=0
For UBound(a) + 1
ii = ii + a(i)
i = i + 1
Next
均值 = ii /( UBound(a) + 1)
i=0
For UBound(a)
If Abs(均值 - a(i)) > Abs(均值 - a(i + 1)) Then
ii = a(i + 1)
ElseIf Abs(均值 - a(i)) < Abs(均值 - a(i + 1)) Then
ii = a(i)
End If
i=i+1
Next
MsgBox ii


16、有一个字符串,里面包含一些数字,写一个函数,把这些数字加起来。比如“我30你40他50”结果就是120。请写出代码
a = "我30你40他50ni"
For i = 1 To Len(a) + 1
If IsNumeric(Mid(a, i, 1)) = True Then
ii = ii & Mid(a, i, 1)
Else
b = b + ii
ii = 0
End If
Next
Msgbox b


17、遍历字符串"A1a2d5m8Qz",取出所有小写字母及数字,并按照与原来相反的顺序拼接成新的字符串,请写出代码
MsgBox 反提取小写数字("A1a2d5m8Qz")

Function 反提取小写数字(字符)
i = Len(字符)
For Len(字符)
If (Asc(mid(字符,i,1)) > 96 and Asc(mid(字符,i,1)) < 123 ) or (Asc(mid(字符,i,1)) > 47 and Asc(mid(字

符,i,1)) < 58 ) Then
反提取小写数字 = 反提取小写数字 & mid(字符, i, 1)
End If
i = i - 1
Next
End Function


//1、遍历字符串"A1a2d5m8Qz",取出所有小写字母及数字,并按照与原来相反的顺序拼接成新的字符串,请写出代码
Function getNewStr(str)
Dim ac, nstr, ns
nstr = ""
For i = len(str) To 1 Step - 1
ns = Mid(str, i, 1)
ac = Asc(ns)
If (ac > 96 and ac < 123) or (ac > 47 and ac < 58) Then
nstr = nstr + ns
End If
Next
getNewStr = nstr
End Function
'MessageBox getNewStr("A1a2d5m8Qz")
//2、有一个字符串,里面包含一些

数字,写一个函数,把这些数字加起来。比如“我30你40他50”结果就是120。请写出代码
Function getSum(str)
Dim ns, nst, num
nst = "" : num = 0
For i = 1 To len(str)
ns = Mid(str, i, 1)
If IsNumeric(ns) Then
nst = nst + ns
Else
num = num + Clng(nst)
nst = ""
End If
Next
num = num + CLng(nst)
getSum = num
End Function
'MessageBox getSum("我30你40他50")
//3、获取数组array(10,9,1,5,2,3,4,5,6,11)中最接近平均数的值,请写出代码
Function getNum(ary)
Dim num, ab, temp, nm
num = eval(join(ary, "+")) / UBound(ary)
For i = 0 To UBound(ary)
If i = 0 Then
ab = Abs(ary(i) - num)
End If
temp = Abs(ary(i) - num)
If ab > temp Then
ab = temp
nm = ary(i)
End If
Next
getNum = nm
End Function
'MessageBox getNum(array(10, 9, 1, 5, 2, 3, 4, 5, 6, 11))
//4、写一个函数,可以让普通窗口(例如记事本)在屏幕内移动,碰到屏幕边缘随机反向移动(类似屏幕保护的汽泡程序),请写出
Function moveWin(Hwnd)
Dim ary, h, w, maxh, maxw, fa, fb
ScreenW = Plugin.GetSysInfo.GetScreenResolutionX()
ScreenH = Plugin.GetSysInfo.GetScreenResolutionY()
sRect = Plugin.Window.GetWindowRect(Hwnd)
ary = Split(sRect, "|")
W1 = Clng(ary(0)): H1 = Clng(ary(1))
W2 = Clng(ary(2)) : H2 = Clng(ary(3))
w = W2 - W1 : h = H2 - H1
fa = true : fa = true
Call Plugin.Window.Active(Hwnd)
Call Plugin.Window.Show(Hwnd)
Do
Randomize
If fa Then
W1 = Round(Rnd * 5) + W1
Else
W1 = W1 - Round(Rnd * 5)
End If
If fb Then
H1 = Round(Rnd * 5) + H1
Else
H1 = H1 - Round(Rnd * 5)
End If
maxw = w + W1 : maxh = h + H1
If W1 <= 0 Then
W1 = 0
fa = true
End If
If H1 <= 0 Then
H1 = 0
fb = true
End If
If maxw >= ScreenW Then
W1 = ScreenW - w
fa = false
End If
If maxh >= ScreenH Then
H1 = ScreenH - h
fb = false
End If
Call Plugin.Window.Move(Hwnd, W1, H1)
Delay 10
Loop
End Function
//Call RunApp("notepad.exe")
//Delay 1000
//Hwnd = Plugin.Window.Find("Notepad", 0)
//If Hwnd > 0 Then
// moveWin(Hwnd)
//Else
// MessageBox "记事本未找到!"
//End If
'5、锁定鼠标位置在(200,300)到(500,600)之间,超出范围则回到边界(鼠标范围锁定),请写出代码
Function clockMouse(x1,y1,x2,y2)
Do
GetCursorPos x, y
If x < x1 Then
x = x1
End If
If x > x2 Then
x = x2
End If
If y < y1 Then

y = y1
End If
If y > y2 Then
y = y2
End If
MoveTo x, y
Delay 1
loop
End Function
//Call clockMouse(200,300,500,600)
'6、鼠标按圆型移动,半径为r=100,圆点为(200,200),请写出代码.
Function drwCircle(radius, centreX, centreY)
Dim i : i = 0
Do
MoveTo centreX + radius * cos(i * 3.14159 / 180), centreY + radius * sin(i * 3.14159 / 180)
i = i + 1
If i = 360 Then : i = 0 : End If
Delay 2
Loop
End Function
'Call drwCircle(100, 200, 200)
'7、随即生成一个1~100之间的整数,玩家可以通过inputbox输入数字,猜对则退出游戏,猜错则提示答案的范围(猜数游戏),请
//
//写出代码
//例如:
//随机数为:60,用户输入20,程序提示"答案范围为:20~100".
//用户再次输入75,程序提示"答案范围为:20~75".
//用户再次输入60,程序提示"猜中",然后退出程序.
Function gueNum()
Dim rd, inpt, maxn, minn
minn = 0 : maxn = 100
Randomize
rd = int(Rnd * 100) + 1
inpt = Cint(InputBox("(猜数游戏),输入1~100之间的整数,玩家可以通过输入数字,猜对则退出游戏,猜错则提示答案的范围"))
Do
If inpt = rd Then
MsgBox rd & ",恭喜答对了"
EndScript
ElseIf inpt > rd and maxn > inpt Then
maxn = inpt
ElseIf inpt < rd and minn < inpt Then
minn = inpt
End If
Delay 100
inpt = Cint(InputBox("答案范围为:" & minn & "~" & maxn))
Loop
End Function
'Call gueNum()
'写一个子程序,可以使鼠标从当前的坐标逐点的移动到目的坐标(带轨迹的鼠标移动),请写出代码
Sub moveMou(x, y)
Dim fa, fb, xx, yy, maxl
GetCursorPos x0, y0
xx = Abs(x0 - x)
yy = Abs(y0 - y)
If xx > yy Then
maxl = xx
Else
maxl = yy
End If
MessageBox maxl
If x0 < x Then
fa = 1
Else
fa = - 1
End If
If y0 < y Then
fb = 1
Else
fb = - 1
End If
For maxl
If x0
x0 = x0 + fa
y0 = y0 + fb
MoveTo x0, y0
Delay 10
Next
End Sub
Call moveMou(1000,500)

相关文档