rreading=1
const forwriting=2
const forappending=8
Dim objShell
Dim MyArray, Rx, Ry
Dim KeyYouPress
Set objShell = CreateObject("WScript.Shell")
//DirPath = objShell.SpecialFolders.Item("DeskTop")
DirPath = "E:\特征码"
MsgStr = "按 Esc 键退出键码测试"
MsgStr = MsgStr & vbCrlf & "按 F1 键进行特征码抓取"
MsgStr = MsgStr & vbCrlf & "按 F2 键进行特征码验证"
MsgStr = MsgStr & vbCrlf & "按 F3 键进行按键码值测试"
Do While true
MessageBox MsgStr
KeyYouPress = WaitKey()
If KeyYouPress = 27 then
MessageBox "退出主程序!"
Exit Do
End If
If KeyYouPress = 114 then
Call AscIIOfKey()
End If
If KeyYouPress = 112 then
FileName = InputBox("请输入"&vbCrlf&"所取特征物想要保存的"&vbCrlf&"文本文件名称!","文件保存")
FileName = LTrim( RTrim( FileName ) ) & ".txt"
Call Get_Features( DirPath, FileName )
End If
If KeyYouPress = 113 then
FileName = InputBox("请输入"&vbCrlf&"所取特征物想要保存的"&vbCrlf&"文本文件名称!","文件保存")
FileName = LTrim( RTrim( FileName ) ) & ".txt"
XY = IsFeaturesExists( DirPath, FileName)
if left( XY, 1) = "-" then
MessageBox "没有找到!"
Else
MyArray = Split(XY,"|")
Rx = CInt( MyArray(0) )
Ry = CInt( MyArray(1) )
MessageBox "找到了,坐标为: " & Rx&","&Ry
End if
End If
Loop
EndScript
Function IsFeaturesExists( DirPath, FileName)
Dim objShell, fso, MyArray
Dim fSourceName, fTargetname
Dim Rx(100), Ry(100), Rs(100)
Dim PixelColor(100), Features(100)
Dim Num
fTargetname = DirPath & "\" & "对比结果.txt"
fSourceName = DirPath & "\" & FileName
Set objShell = CreateObject("WScript.Shell")
//↑取得桌面路径
set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists( fSourceName )=0
IsFeaturesExists = "-2|-2"
Goto EndOfFunc
End If
//↑文件不存在
Set fSource = fso.OpenTextFile( fSourceName, ForReading, True)
Num = 0 //记录有效记录数
While fSource.AtEndOfStream<>true
sLine = trim( fSource.ReadLine() )
If Left( sLine, 2 ) <> "//" Then
Num = Num + 1
MyArray = Split( sLine, "," )
Rx(Num) = CInt( MyArray(0) )
Ry(Num) = CInt( MyArray(1) )
Features(Num) = MyArray(2)
PixelColor(Num)=GetPixelColor( Rx(Num), Ry(Num) )
// PosOfSeparator = InStr( sLine, ",")
// Rx(Num) = Clng( Left( sLine, PosOfSeparator - 1 ))
// sLine = right( sLine, len( sLine ) - PosOfSeparator )
// PosOfSeparator = InStr( sLine, ",")
// Ry(Num) = Clng( Left( sLine, PosOfSeparator - 1 ))
// Features(Num) = right( sLine, len( sLine ) - PosOfSeparator )
// PixelColor(Num)=GetPixelColor( Rx(Num), Ry(Num) )
//// ↑上面这段跟使用数组效果是一样的
End If
Wend
//↑上面就是读文件并处理
If fso.FileExists( fTargetname )=0
Set fTarget = fso.OpenTextFile( fTargetName, ForWriting, True)
fTarget.Close
Else
set fTarget=fso.opentextfile( fTargetName,forreading)