2014-02-14 72 views
0

我正在使用鼠標代碼。我正試圖將鼠標移動到外部應用程序點或使其進入外部應用程序的按鈕?例如,將它移動到一個Windows計算器按鈕,並用程序按下它。設置光標去外部應用程序,使用外部程序

有沒有辦法在外部應用程序上調用按鈕或將焦點更改爲使用vb的另一個應用程序?

+0

你谷歌第一,沒有找到答案? –

+0

是的。我谷歌第一,我發現只有1個答案,但我不知道如何發送消息給鼠標(使用win32)。 – terror

回答

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 

按下鼠標和鼠標了事件模擬點擊按鈕。希望有幫助

valter