Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2005
    Messaggi
    197

    [vb.net] simulare il click a coordinate

    salve vorrei eseguire una simulazione del left click del mouse a coordinate ben precise, e ho dfifficolta a fare cio protreste aiutarmi

  2. #2
    Non esiste un metodo nativo; al massimo puoi arrangiarti con l'API mouse_event.
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2005
    Messaggi
    197
    nn so come fare ad esempio su vb6.0 ho risolto con delle api ma qui su vb.net nn so inserire le api

  4. #4
    Usa i normali declare tenendo conto che i tipi di dato sono cambiati.
    Amaro C++, il gusto pieno dell'undefined behavior.

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2005
    Messaggi
    197
    qulache code simple nn ci ho capito niente

  6. #6
    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
    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:
            Dim pnt As Drawing.Point
            pnt = Me.PointToScreen(Button1.Location)
            SimulateClick(pnt)
    Questo era l'approccio "forza bruta". Credo che si possa fare anche smanettando con i messaggi di Windows, ora ci do un'occhiata...
    Amaro C++, il gusto pieno dell'undefined behavior.

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2005
    Messaggi
    197
    ma mi interessa lo spostamento e il click fuori dal form in tutto l'ambiente windows

  8. #8
    Originariamente inviato da MItaly
    Per simulare il click basta chiamare SimulateClick passandole come argomento il punto (relativo allo schermo) da "cliccare".
    Amaro C++, il gusto pieno dell'undefined behavior.

  9. #9
    Utente di HTML.it
    Registrato dal
    May 2008
    Messaggi
    8
    E' possibile oltre che spostare il muose utilizzando la funzione SimulateClick anche ottene le coordinate di dove si trova il muose??

    Grazie
    Mille

  10. #10
    Utente di HTML.it L'avatar di Tuco
    Registrato dal
    Sep 2005
    Messaggi
    199
    io ho trovato questo codice..ma non so se funziona.,

    Dim MyPointAPI As POINTAPI
    Private Type POINTAPI
    X As Long
    Y As Long
    End Type

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

    Public Sub Timer1_Timer()
    l = GetCursorPos(MyPointAPI)
    Label1.Caption = CStr(MyPointAPI.X) & ", " & CStr(MyPointAPI.Y)
    End Sub
    Il mondo si divide in due categorie: chi ha la pistola carica e chi no...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.