求用WinIo做的VB小程序(带源码)

条件很简单,每当Timer1到期驱动级模拟左键按下,上传在这里。
2025-03-03 18:30:00
推荐回答(2个)
回答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
    '按F11开启功能,按F12关闭功能,如果不需要这样,将上两行删除即可
    
    If bolStage And (GetTickCount - lngTimer) >= 1000 Then '此处的1000表示每一秒执行一次,如有改动修改此参数即可。
        lngTimer = GetTickCount
        'SetCursorPos 288, 718     '设置鼠标位置(1024X768)
        mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0    '单击时用左按键下or左按键上,双击时写两句
    End If
End Sub

在窗体添加一个Timer控件并将上述代码复制上就行了。

回答2:

我到现在还不明白你所谓的驱动级.左键是鼠标左键吗?如果是,那在Timer事件中写鼠标单击出发事件就好了,何必搞得这么大费周章,还API的、驱动级的搞一大堆.
驱动鼠标事件是指要寻找是否有鼠标吗?或者是安装鼠标设备吗?又或者是.....