vb后台模拟按键 F11开始运行 F12停止运行 每隔1秒自动输入“,” 和鼠标左键
1个回答
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询