我想用VB编写一个自动按某个按钮的程序,具体如下: 每隔4秒按一次E键,循环执行,直到按下终止热键。
3个回答
展开全部
请把下面的代码放在文本里,保存,然后改后缀名为.frm格式,打开
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3030
ClientLeft = 120
ClientTop = 450
ClientWidth = 4560
LinkTopic = "Form1"
ScaleHeight = 3030
ScaleWidth = 4560
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer2
Left = 1920
Top = 1920
End
Begin VB.TextBox Text1
Height = 495
Left = 360
TabIndex = 0
Top = 1080
Width = 3735
End
Begin VB.Timer Timer1
Left = 1560
Top = 1920
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer2.Interval = 100
Timer2.Enabled = True
Timer1.Interval = 4000
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
SendKeys "{E}"
End Sub
Private Sub Timer2_Timer()
If GetAsyncKeyState(vbKeyCtrl + vbKeyF10) Then
Timer1.Enabled = True
ElseIf GetAsyncKeyState(vbKeyCtrl + vbKeyF12) Then
Timer1.Enabled = False
End If
End Sub
希望可以帮到你,满意请采纳,有问题请追问^_^
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3030
ClientLeft = 120
ClientTop = 450
ClientWidth = 4560
LinkTopic = "Form1"
ScaleHeight = 3030
ScaleWidth = 4560
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer2
Left = 1920
Top = 1920
End
Begin VB.TextBox Text1
Height = 495
Left = 360
TabIndex = 0
Top = 1080
Width = 3735
End
Begin VB.Timer Timer1
Left = 1560
Top = 1920
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer2.Interval = 100
Timer2.Enabled = True
Timer1.Interval = 4000
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
SendKeys "{E}"
End Sub
Private Sub Timer2_Timer()
If GetAsyncKeyState(vbKeyCtrl + vbKeyF10) Then
Timer1.Enabled = True
ElseIf GetAsyncKeyState(vbKeyCtrl + vbKeyF12) Then
Timer1.Enabled = False
End If
End Sub
希望可以帮到你,满意请采纳,有问题请追问^_^
追问
如果我不是要在本窗体执行这个命令,而是在其它程序里面执行这个命令呢?应该怎么激活?
追答
这段代码是扫描按键,只要你打开这个程序,无论是否有焦点,只要按到CTRL+F10就可以激活
展开全部
设置两个菜单项,快捷键为CTRL+F10和CTRL+F12,然后用它们控制Timer
Private Sub Timer1_Timer()
SendKeys "{Enter}"
End Sub
Private Sub Timer1_Timer()
SendKeys "{Enter}"
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
编这个用按键精灵啊,看了就会不用教的。
用vb也可以添加一个time控件interval 4000
双击它输入代码就可以啦
用vb也可以添加一个time控件interval 4000
双击它输入代码就可以啦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询