VB中如何虚拟按下鼠标左键

点按钮就虚拟按下鼠标左键
2024-12-02 08:06:29
推荐回答(3个)
回答1:

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim anctlejiang As Long '这句写到通用里
Private Sub Command1_Click()
PostMessage 65674, 100, 17, 0 '这个是按下CTLE键
anctlejiang = 1

Sleep 1000 '延迟1秒
PostMessage 65674, 101, 17, 0 '弹起CTLE键
anctlejiang = 0
End Sub

Private Sub Timer1_Timer()
MsgBox anctlejiang
If anctlejiang <> 0 Then
Dim aa As Long
PostMessage 65674, 201, 1, 0 '这个是按下左键
Label1.Caption = "以按下左键"
aa = anctlejian
If aa <> anctlejian Then
PostMessage 65674, 202, 1, 0 '弹起左键
Label1.Caption = "以弹起左键"
End If
End If
End Sub
是否可以解决您的问题?

回答2:

下面两个的答案一点用都没有。

模拟鼠标操作首先你要先把鼠标移到正确位置。
SetCursorPos '这个API可以解决问题
然后就是模拟点击
mouse_event '这个API就可以模拟点击了

回答3:

QUN号148317126 ,2000个人的,那里问问