vb后台模拟按键 F11开始运行 F12停止运行 每隔1秒自动输入“,” 和鼠标左键

 我来答
信心安J
2013-05-01 · TA获得超过402个赞
知道小有建树答主
回答量:787
采纳率:0%
帮助的人:722万
展开全部
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Dim key1 As Integer
Dim key2 As Integer
Dim bolStage As Boolean
Dim lngTimer As Long
Private Sub Form_Load()
Timer1.Interval = 10
Timer1.Enabled = True
'Me.Visible = False
key1 = GetKeyState(vbKeyF11)
key2 = GetKeyState(vbKeyF12)
lngTimer = GetTickCount
End Sub

Private Sub Timer1_Timer()
If GetKeyState(vbKeyF11) <> key1 Then key1 = GetKeyState(vbKeyF11): bolStage = True: Beep
If GetKeyState(vbKeyF12) <> key2 Then key2 = GetKeyState(vbKeyF12): bolStage = False: Beep

If bolStage And (GetTickCount - lngTimer) >= 1000 Then
lngTimer = GetTickCount
SendKeys ","
'SetCursorPos 288, 718 '设置鼠标位置(1024X768)
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '单击时用左按键下or左按键上,双击时写两句
End If
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式