문제

I am working with mouse code. I am trying to move a mouse to an external application point or make it go to button from external application? For example, move it to a windows calculator button and press it with a program.

Is there a way to invoke a button press on an external application or change the focus to another application using vb?

도움이 되었습니까?

해결책

If you know the position of the button to click, lets say x,y in screen coordinates you can do:

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

The mouse down and mouse up events simulate the click of the button. Hope that helps

valter

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top