我正在使用鼠标代码。我试图将鼠标移动到外部应用程序点或从外部应用程序转到按钮?例如,将其移动到Windows计算器按钮并按下程序。
有没有办法在外部应用程序上调用按钮按下或使用vb将焦点更改为其他应用程序?
答案 0 :(得分:1)
如果你知道点击按钮的位置,可以在屏幕坐标中说x,y:
Public Declare Auto Function SetCursorPos Lib "User32.dll" _
(ByVal X As Integer, ByVal Y As Integer) As Long
Public Declare Auto Function GetCursorPos Lib "User32.dll" _
(ByRef lpPoint As Point) As Long
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" _
(ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
SetCursorPos(x, y) 'moves cursor to x,y position
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 'Invoke mouse down event
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 'Invoke mouse up event
鼠标按下和鼠标按下事件模拟按钮的单击。希望有所帮助
瓦尔特