请教用VB编写一个自动按键小程序
一个滚动显示各种信息的窗口‘消息”,当其出现‘请按F1,F2'时,需手动按F1F2,请用VB编写代码,实现检测到窗口中出现上述信息时,自动按F1和F2. 展开
程序包含一个标签和一个间隔1秒的时间控件...
Private xx(1 To 5) As String
Private i As Integer, f As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 112 Then
f = MsgBox("你按了F1,继续吗?", vbYesNo + vbInformation, "提示")
If f = vbYes Then
Timer1.Enabled = True
Else
Call Form_KeyDown(113, 0)
End If
ElseIf KeyCode = 113 Then
MsgBox "你按了F2键,结束应用程序!"
End
End If
End Sub
Private Sub Form_Load()
xx(1) = "aaaaaaaaaa"
xx(2) = "bbbbbbbbbb"
xx(3) = "cccccccccc"
xx(4) = "dddddddddd"
xx(5) = "请按F1、F2"
i = 1
End Sub
Private Sub Timer1_Timer()
Label1.Caption = xx(i)
If xx(i) = "请按F1、F2" Then
Timer1.Enabled = False
Call Form_KeyDown(112, 0)
End If
i = i + 1
If i > 5 Then i = 1
End Sub
你也可以手动按F1、F2 效果一样!
2024-09-19 广告