放羊的狼 发表于 2022-11-17 08:58

关于vba中mouse_event函数按下QQ截图键后的问题

代码如下,在sendkeys按下截图组合键后鼠标坐标会执行,但鼠标左键按下和抬起的两个动作不执行,不知道是什么原因,希望有大佬能帮助一下。

Public 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)
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Const MouseEventf_LeftDown = &H2   '按下左键
Public Const MouseEventf_LeftUp = &H4       '弹起左键

Type POINTAPI
    x As Long
    y As Long
End Type

Public Function 移动到(x As Long, y As Long)
    SetCursorPos x, y
End Function

Public Function getmouse_x_y() As POINTAPI    '坐标
    GetCursorPos getmouse_x_y
End Function

Public Function 左单击(单击次数 As Long)
    For MKi = 1 To 单击次数
      mouse_event MouseEventf_LeftDown, 0, 0, 0&, 0&
      mouse_event MouseEventf_LeftUp, 0, 0, 0&, 0&
    Next MKi
End Function

Sub test()
    移动到 450, 230   '移动到截图起始位
    SendKeys ("^%a")    '组合键截图
'    左单击 1
    mouse_event MouseEventf_LeftDown, 0, 0, 0&, 0&'按下开始截图
   
'    delay 1
   
    移动到 1300, 1030   '移动到截图末位
   
    mouse_event MouseEventf_LeftUp, 0, 0, 0&, 0&    '松开左键
   
    '滚动鼠标滚轮
End Sub

放羊的狼 发表于 2022-11-17 14:09

{:1_900:}没大佬回复一下么....

fengtian99 发表于 2023-2-14 09:29

设置一点延迟时间试试
页: [1]
查看完整版本: 关于vba中mouse_event函数按下QQ截图键后的问题