Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub form1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 113'表示按下F2
Timer1.Enabled = True
Case 114
Timer1.Enabled = False '按下F3
End Select
End Sub
Private Sub Timer1_Timer()
SendKeys "{F8}"
Sleep 500
SendKeys "1"
Sleep 500
SendKeys "{ENTER}"
End Sub
如果是全局热键,稍微麻烦点,不过我这里也有现成的代码。你加我百度HI我传给你.
Dim fStop As BooleanPrivate Sub Command1_Click() '开始
Do
DoEvents
Loop Until fStop
End Sub
Private Sub Command2_Click() '停止
fStop = True
End Sub
添加两个Timer控件(Timer1和Timer2),再添加一个Label1,然后复制→粘贴,点击【是】,创建控件数组,也就变成4个Label了。参考代码如下:
Dim i As Integer, k As Integer
Private Sub Command1_Click()
Timer2.Enabled = True
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
Timer1.Interval = 600
Timer2.Interval = 1000
End Sub
Private Sub Timer1_Timer()
lblDisp(i).Caption = StrConv(i + 1, vbWide)
i = i + 1
If i = 4 Then Timer1.Enabled = False
End Sub
Private Sub Timer2_Timer()
lblDisp(k).Caption = k + 1
k = k + 1
If k = 4 Then Timer2.Enabled = False: Timer1.Enabled = True
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)