求一个简单的按键精灵脚本
看似简单实则属于高级应用,涉及到多线程编程。另外时序方面要控制得准确也是非常困难的,因为脚本解释本身需要消耗CPU时间,按键操作延时等等都会影响精度。
代码如下
Dim TH0//线程0句柄
Dim TH1//线程1句柄
Dim TH2//线程2句柄
Dimenv TKey0//线程0按键
Dimenv TKey1//线程1按键
Dimenv TKey2//线程2按键
DimEnv GAP1//线程1间隔时间
DimEnv GAP2//线程2间隔时间
Dimenv isRun//运行标志
Dimenv T1//时间记录1
Dimenv T2//时间记录2
TKey0 = "1"//初始化按键码0
TKey1 = "2"//初始化按键码1
TKey2 = "3"//初始化按键码2
GAP1=5//设置间隔1
GAP2=10//设置间隔2
//启动线程
TH0 = BeginThread(AlwaysClick)
TH1 = BeginThread(TimingClick1)
TH2 = BeginThread(TimingClick2)
isRun = 1//开始循环
While isRun
IF GetLastKey=27 Then isRun = 0//按ESC结束
Delay 10
Wend
StopThread TH0
StopThread TH1
StopThread TH2
EndScript
//================================
Sub AlwaysClick()
While isRun
KeyPress TKey0,1
Delay 10
wend
End Sub
Sub TimingClick1()
Dim SP
Dim T
T1=now
While isRun
T=now
SP =(T-T1)*100000
If (SP) >= GAP1 Then
KeyPress TKey1, 1
TracePrint "定时按键1时间:" & T
T1=T
End If
Delay GAP1*10
Wend
End Sub
Sub TimingClick2()
Dim SP
Dim T
T2=now
While isRun
T=now
SP =(T-T2)*100000
If (SP) >= GAP2 Then
KeyPress TKey2, 1
TracePrint "定时按键2时间:" & T
T2=T
End If
Delay GAP2 * 10
Wend
End Sub
2022-03-17 广告