Mausklick simulieren Problem lösen!



  • Man sollte jetzt mal endlich anfangen eine Lösung zu finden wie so etwas geht! Ich mache mal den Anfang:

    Private Type POINTAPI
      X As Long
      Y As Long
    End Type
    
    Private Declare Function ClientToScreen Lib "user32" ( _
        ByVal hWnd As Long, lpPoint As POINTAPI) As Long
    Private Declare Sub mouse_event Lib "user32" ( _
        ByVal dwFlags As Long, _
        ByVal dx As Long, ByVal dy As Long, _
        ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Declare Function SetCursorPos Lib "user32" ( _
        ByVal X As Long, ByVal Y As Long) As Long
    
    Public Sub MouseClick(Optional ByRef ctl As Control)
      Const MOUSEEVENT_LEFTDOWN = &H2
      Const MOUSEEVENT_LEFTUP = &H4
      Dim Point As POINTAPI
    
      If Not ctl Is Nothing Then
        'Mitte des Controls bestimmen (in Pixel):
        With ctl.Parent
          Point.X = _
              .ScaleX(ctl.Width, vbTwips, vbPixels) \ 2
          Point.Y = _
              .ScaleY(ctl.Height, vbTwips, vbPixels) \ 2
        End With
    
        'Maus positionieren:
        ClientToScreen ctl.hWnd, Point
        SetCursorPos Point.X, Point.Y
      End If
    
      'Klick-Ereignis generieren:
      mouse_event MOUSEEVENT_LEFTDOWN, 0, 0, 0, 0
      DoEvents
      mouse_event MOUSEEVENT_LEFTUP, 0, 0, 0, 0
    End Sub
    

    Das hier ist allerdings ein Visual Basic Code! Den habe ich von diese Seite: http://vb-tec.de/mausclk.htm. Jetzt müsste nur noch jemand diesen Code in C++ formatieren! 🙄



  • Dann habe ich noch das gefunden: http://www.germandevnet.de/html/faq/cpp/winapi/tast.htm

    und das hier: http://www.delphi-board.profihost.de/board/showtopic.php?threadid=2689

    [ Dieser Beitrag wurde am 19.08.2002 um 12:22 Uhr von pkeamorpheus editiert. ]



  • Das "Mausklick"-Problem wurde hier schon tausend mal gelöst 😉
    Da mich das selber aber weniger interessiert, rate ich einfach mal ne Lösung:

    int Mausklick(int x, int y)
    {
       SetCursorPos(x,y);
       mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
       mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
    }
    


  • Es geht dir also nur darum nen Mausklick zu simulieren??
    Dafür brauchst doch nichts übersetzen, sondern nur die letzten Zeilen ansehen:

    'Klick-Ereignis generieren:
      mouse_event MOUSEEVENT_LEFTDOWN, 0, 0, 0, 0
      DoEvents
      mouse_event MOUSEEVENT_LEFTUP, 0, 0, 0, 0
    

    Kleiner blick in das P-SDK:

    mouse_event
    The mouse_event function synthesizes mouse motion and button clicks.

    Windows NT: This function has been superseded. Use SendInput instead.

    VOID mouse_event(
    DWORD dwFlags, // flags specifying various motion/click variants
    DWORD dx, // horizontal mouse position or position change
    DWORD dy, // vertical mouse position or position change
    DWORD dwData, // amount of wheel movement
    DWORD dwExtraInfo
    // 32 bits of application-defined information
    );

    Parameters
    dwFlags
    A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values: Value Meaning
    MOUSEEVENTF_ABSOLUTE Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
    MOUSEEVENTF_MOVE Specifies that movement occurred.
    MOUSEEVENTF_LEFTDOWN Specifies that the left button is down.
    MOUSEEVENTF_LEFTUP Specifies that the left button is up.
    MOUSEEVENTF_RIGHTDOWN Specifies that the right button is down.
    MOUSEEVENTF_RIGHTUP Specifies that the right button is up.
    MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button is down.
    MOUSEEVENTF_MIDDLEUP Specifies that the middle button is up.
    MOUSEEVENTF_WHEEL Windows NT: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData

    dx
    Specifies the mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual x-coordinate; relative data is given as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.
    dy
    Specifies the mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual y-coordinate; relative data is given as the number of mickeys moved.
    dwData
    If dwFlags is MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
    If dwFlags is not MOUSEEVENTF_WHEEL, then dwData should be zero.

    dwExtraInfo
    Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.

    😉



  • Warum werden aber solche dinge nicht ins FAQ gestellt?

    P.S. Wenn mal ein Admin in diesem Beitrag: Uhrzeit die 4 Zeile umändern könnt weil sonst bei der Uhrzeit die 0 nicht angezeigt wird (jedenfalls in DOS nicht!) So muss es richtig heissen:

    wsprintf(uhrzeit, "%02d:%02d:%02d", systime.wHour, systime.wMinute, systime.wSecond);
    

    Danke


Anmelden zum Antworten