Per simulare il click basta chiamare SimulateClick passandole come argomento il punto (relativo allo schermo) da "cliccare". Per cliccare il pulsante Button1, ad esempio, basterà fare così:codice:Enum meFlags As Integer MOUSEEVENTF_MOVE = &H1 MOUSEEVENTF_LEFTDOWN = &H2 MOUSEEVENTF_LEFTUP = &H4 MOUSEEVENTF_RIGHTDOWN = &H8 MOUSEEVENTF_RIGHTUP = &H10 MOUSEEVENTF_MIDDLEDOWN = &H20 MOUSEEVENTF_MIDDLEUP = &H40 MOUSEEVENTF_XDOWN = &H80 MOUSEEVENTF_XUP = &H100 MOUSEEVENTF_WHEEL = &H800 MOUSEEVENTF_VIRTUALDESK = &H4000 MOUSEEVENTF_ABSOLUTE = &H8000 End Enum Declare Sub mouse_event Lib "user32" (ByVal dwFlags As meFlags, ByVal Coords As Drawing.Point, ByVal dwData As Integer, ByVal dwExtraInfo As UIntPtr) Sub SimulateClick(ByVal Location As Drawing.Point) Dim trect As Drawing.Rectangle = Screen.GetBounds(Location) Dim tpnt As New Drawing.Point(65535.0 / trect.Width * Location.X, 65535.0 / trect.Height * Location.Y) mouse_event(meFlags.MOUSEEVENTF_MOVE Or meFlags.MOUSEEVENTF_ABSOLUTE, tpnt, 0, New UIntPtr(Convert.ToUInt32(0))) mouse_event(meFlags.MOUSEEVENTF_LEFTDOWN Or meFlags.MOUSEEVENTF_ABSOLUTE, tpnt, 0, New UIntPtr(Convert.ToUInt32(0))) mouse_event(meFlags.MOUSEEVENTF_LEFTUP Or meFlags.MOUSEEVENTF_ABSOLUTE, tpnt, 0, New UIntPtr(Convert.ToUInt32(0))) End Sub
Questo era l'approccio "forza bruta". Credo che si possa fare anche smanettando con i messaggi di Windows, ora ci do un'occhiata...codice:Dim pnt As Drawing.Point pnt = Me.PointToScreen(Button1.Location) SimulateClick(pnt)

Rispondi quotando