Mausweg mit Maustaste ermitteln

  • Hallo Leute,
    da ich mich erst seit 2 Wochen mit Autoit beschäftige, verzeiht mir erstmal meinen Programmierstil.

    Mein Problem das ich habe das ich den Mausweg wissen will in meinem Script.
    Gedacht ist es so:
    Linke Maustaste gedrückt -> Anfangsposition speichern -> Linke Maustaste losgelassen -> Endposition speichern
    Aber sobald ich drücke spuckt er mir meine Msgbox zum testen aus.
    Vielleicht kennt einer von euch eine funktionierende Lösung

    Das ganze findet Verwendung in einem Bild-Slider-Script mit der Hilfe von QuickDraw.

    Im Anhang ist ein Archiv mit allen Dateien um das Script zum laufen zu bringen.

    Code:

    Spoiler anzeigen
    [autoit]


    #AutoIt3Wrapper_usex64=n

    [/autoit] [autoit][/autoit] [autoit]

    #Include <Memory.au3>
    #include <Array.au3>
    #include <GDIPlus.au3>
    #Include <Misc.au3>
    #include <QuickDraw.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Exit")
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $dll = DllOpen("user32.dll")
    $anzahlbilder = 12;Anzahl der Bilder im Verzeichniss pics
    $z = 1;Bild was als erstes angezeigt wird

    [/autoit] [autoit][/autoit] [autoit]

    Global $anfangmaus = 0
    Global $endemaus = 0
    Global $gedrueckt =0

    [/autoit] [autoit][/autoit] [autoit]

    Global $pos[5][3] ;Bilderpositionen

    [/autoit] [autoit][/autoit] [autoit]

    $pos[0][0] = 150
    $pos[0][1] = 250
    $pos[0][2] = 150
    $pos[1][0] = 225
    $pos[1][1] = 200
    $pos[1][2] = 225
    $pos[2][0] = 450
    $pos[2][1] = 150
    $pos[2][2] = 300
    $pos[3][0] = 750
    $pos[3][1] = 200
    $pos[3][2] = 225
    $pos[4][0] = 900
    $pos[4][1] = 250
    $pos[4][2] = 150

    [/autoit] [autoit][/autoit] [autoit]

    _QuickDraw_Enable("Quickdraw Slider",1200,500,200,200,False) ; Quickdraw Fenster erstellen
    GUISetOnEvent(-1, "_Exit")
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _QuickDraw_ClearBuffer(0xFF000000)
    _showpics($z, $anzahlbilder);Die ersten Bilder anzeigen
    _QuickDraw_SwapBuffers()

    [/autoit] [autoit][/autoit] [autoit]

    While _QuickDraw_Running()

    [/autoit] [autoit][/autoit] [autoit]

    ;Problemzone Anfang
    $mouse_pos= _QuickDraw_GetMousePos(-1)
    $druck=_IsPressed(01,$dll)
    ;$druck=_QuickDraw_GetMouseLeft()
    ToolTip($mouse_pos[0]&","&$mouse_pos[1]&"::"& $druck,0,0)

    [/autoit] [autoit][/autoit] [autoit]

    If $anfangmaus = 0 And $druck = "True" Then
    $anfangmaus = $mouse_pos[0]
    $gedrueckt = 1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $gedrueckt = 1 And $druck = "False" Then
    $endemaus = $mouse_pos[0]
    MsgBox (0,"Test",$anfangmaus & " bis " & $endemaus)
    $anfangmaus = 0
    $gedrueckt = 0
    EndIf
    ;Problemzone Ende

    [/autoit] [autoit][/autoit] [autoit]

    ;#cs
    ;linkes Bild
    ;Prüfen ob Maus gedrückt im linken Bild von der Mitte
    If $mouse_pos[0] >= $pos[1][0] And $mouse_pos[0] <= ($pos[1][0] + $pos[1][2]) And $mouse_pos[1] >= $pos[1][1] And $mouse_pos[1] <= ($pos[1][1] + $pos[1][2]) And $druck = "True" Then
    _nachrechts($z, $anzahlbilder, 50) ;Bilder nach rechts bewegen
    $z = $z - 1
    If $z < 1 then $z = $anzahlbilder
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ;rechtes Bild
    ;Prüfen ob Maus gedrückt im rechten Bild von der Mitte
    If $mouse_pos[0] >= $pos[3][0] And $mouse_pos[0] <= ($pos[3][0] + $pos[3][2]) And $mouse_pos[1] >= $pos[3][1] And $mouse_pos[1] <= ($pos[3][1] + $pos[3][2]) And $druck = "True" Then
    _nachlinks($z, $anzahlbilder, 50) ;Bilder nach links bewegen
    $z = $z + 1
    If $z > $anzahlbilder Then $z = 1
    EndIf
    ;#ce

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    _Exit()

    [/autoit] [autoit][/autoit] [autoit]

    Func _showpics($nummer, $anzahl)

    [/autoit] [autoit][/autoit] [autoit]

    $picl2 = $nummer - 2
    If $picl2 < 1 then $picl2 = $anzahl - abs($picl2)

    [/autoit] [autoit][/autoit] [autoit]

    $picl =$nummer - 1
    If $picl < 1 then $picl = $anzahl - $picl

    [/autoit] [autoit][/autoit] [autoit]

    $picm = $nummer

    [/autoit] [autoit][/autoit] [autoit]

    $picr = $nummer + 1
    If $picr > $anzahl then $picr = $picr - $anzahl

    [/autoit] [autoit][/autoit] [autoit]

    $picr2 = $nummer +2
    If $picr2 > $anzahl then $picr2 = $picr2 - $anzahl

    [/autoit] [autoit][/autoit] [autoit]

    $piclinks2 = _QuickDraw_LoadTexture("./pics/" & $picl2 & ".jpg")
    $picrechts2 = _QuickDraw_LoadTexture("./pics/" & $picr2 & ".jpg")
    $piclinks = _QuickDraw_LoadTexture("./pics/" & $picl & ".jpg")
    $picrechts = _QuickDraw_LoadTexture("./pics/" & $picr & ".jpg")
    $picmitte = _QuickDraw_LoadTexture("./pics/" & $picm & ".jpg")

    [/autoit] [autoit][/autoit] [autoit]

    _QuickDraw_ClearBuffer(0xFF000000)
    _QuickDraw_Rect($pos[0][0],$pos[0][1], $pos[0][2], $pos[0][2], $piclinks2, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[4][0],$pos[4][1], $pos[4][2], $pos[4][2], $picrechts2, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[1][0],$pos[1][1], $pos[1][2], $pos[1][2], $piclinks, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[3][0],$pos[3][1], $pos[3][2], $pos[3][2], $picrechts, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[2][0],$pos[2][1], $pos[2][2], $pos[2][2], $picmitte, 0xFFFFFFFF)
    _QuickDraw_SwapBuffers()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _nachrechts($nummer, $anzahl, $schritte)

    [/autoit] [autoit][/autoit] [autoit]

    If $nummer < 1 then $nummer = $anzahl
    If $nummer > $anzahlbilder Then $nummer = 1

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $picl3 = $nummer - 3
    If $picl3 < 1 then $picl3 = $anzahl - abs($picl3)

    [/autoit] [autoit][/autoit] [autoit]

    $picl2 = $nummer - 2
    If $picl2 < 1 then $picl2 = $anzahl - abs($picl2)

    [/autoit] [autoit][/autoit] [autoit]

    $picl =$nummer - 1
    If $picl < 1 then $picl = $anzahl - abs($picl)

    [/autoit] [autoit][/autoit] [autoit]

    $picm = $nummer

    [/autoit] [autoit][/autoit] [autoit]

    $picr = $nummer + 1
    If $picr > $anzahl then $picr = $picr - $anzahl

    [/autoit] [autoit][/autoit] [autoit]

    $picr2 = $nummer +2
    If $picr2 > $anzahl then $picr2 = $picr2 - $anzahl

    [/autoit] [autoit][/autoit] [autoit]

    ;MsgBox(0,"" ,$picl3 &","& $picl2 &","& $picl &"," &$picm &","& $picr&","&$picr2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $piclinks3 = _QuickDraw_LoadTexture("./pics/" & $picl3 & ".jpg")
    $piclinks2 = _QuickDraw_LoadTexture("./pics/" & $picl2 & ".jpg")
    $picrechts2 = _QuickDraw_LoadTexture("./pics/" & $picr2 & ".jpg")
    $piclinks = _QuickDraw_LoadTexture("./pics/" & $picl & ".jpg")
    $picrechts = _QuickDraw_LoadTexture("./pics/" & $picr & ".jpg")
    $picmitte = _QuickDraw_LoadTexture("./pics/" & $picm & ".jpg")

    [/autoit] [autoit][/autoit] [autoit]

    ;schritte berechnen
    Dim $schritt[4][3]
    ;Bild 0 zu 1
    $schritt[0][0] = ($pos[1][0] - $pos[0][0]) / $schritte
    $schritt[0][1] = ($pos[0][1] - $pos[1][1]) / $schritte
    $schritt[0][2] = ($pos[1][2] - $pos[0][2]) / $schritte

    [/autoit] [autoit][/autoit] [autoit]

    ;Bild 1 zu 2
    $schritt[1][0] = ($pos[2][0] - $pos[1][0]) / $schritte
    $schritt[1][1] = ($pos[1][1] - $pos[2][1]) / $schritte
    $schritt[1][2] = ($pos[2][2] - $pos[1][2]) / $schritte

    [/autoit] [autoit][/autoit] [autoit]

    ;Bild 2 zu 3
    $schritt[2][0] = ($pos[3][0] - $pos[2][0]) / $schritte
    $schritt[2][1] = ($pos[3][1] - $pos[2][1]) / $schritte
    $schritt[2][2] = ($pos[2][2] - $pos[3][2]) / $schritte

    [/autoit] [autoit][/autoit] [autoit]

    ;Bild 3 zu 4
    $schritt[3][0] = ($pos[4][0] - $pos[3][0]) / $schritte
    $schritt[3][1] = ($pos[4][1] - $pos[3][1]) / $schritte
    $schritt[3][2] = ($pos[3][2] - $pos[4][2]) / $schritte

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $i = 1
    for $i = 1 to $schritte

    [/autoit] [autoit][/autoit] [autoit]

    _QuickDraw_ClearBuffer(0xFF000000)
    _QuickDraw_Rect($pos[0][0], $pos[0][1], $pos[0][2], $pos[0][2], $piclinks3, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[0][0] + $schritt[0][0] * $i ,$pos[0][1] - $schritt[0][1] * $i, $pos[0][2] + $schritt[0][2] * $i, $pos[0][2] + $schritt[0][2] * $i, $piclinks2, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[4][0], $pos[4][1], $pos[4][2], $pos[4][2], $picrechts2, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[1][0] + $schritt[1][0] * $i, $pos[1][1] - $schritt[1][1] * $i, $pos[1][2] + $schritt[1][2] * $i, $pos[1][2] + $schritt[1][2] * $i, $piclinks, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[3][0] + $schritt[3][0] * $i, $pos[3][1] + $schritt[3][1] * $i, $pos[3][2] - $schritt[3][2] * $i, $pos[3][2] - $schritt[3][2] * $i, $picrechts, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[2][0] + $schritt[2][0] * $i, $pos[2][1] + $schritt[2][1] * $i, $pos[2][2] - $schritt[2][2] * $i, $pos[2][2] - $schritt[2][2] * $i, $picmitte, 0xFFFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    _QuickDraw_SwapBuffers()
    sleep(5)

    [/autoit] [autoit][/autoit] [autoit]

    Next

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _nachlinks($nummer, $anzahl, $schritte)

    [/autoit] [autoit][/autoit] [autoit]

    If $nummer < 1 then $z = $anzahl
    If $nummer > $anzahl Then $z = 1

    [/autoit] [autoit][/autoit] [autoit]

    $picl2 = $nummer - 2
    If $picl2 < 1 then $picl2 = $anzahl - abs($picl2)

    [/autoit] [autoit][/autoit] [autoit]

    $picl =$nummer - 1
    If $picl < 1 then $picl = $anzahl - abs($picl)

    [/autoit] [autoit][/autoit] [autoit]

    $picm = $nummer

    [/autoit] [autoit][/autoit] [autoit]

    $picr = $nummer + 1
    If $picr > $anzahl then $picr = $picr - $anzahl

    [/autoit] [autoit][/autoit] [autoit]

    $picr2 = $nummer +2
    If $picr2 > $anzahl then $picr2 = $picr2 - $anzahl

    [/autoit] [autoit][/autoit] [autoit]

    $picr3 = $nummer +3
    If $picr3 > $anzahl then $picr3 = $picr3 - $anzahl

    [/autoit] [autoit][/autoit] [autoit]

    ;MsgBox(0,"" ,$picl2 &","& $picl &"," &$picm &","& $picr&","&$picr2&","&$picr3)

    [/autoit] [autoit][/autoit] [autoit]

    $piclinks2 = _QuickDraw_LoadTexture("./pics/" & $picl2 & ".jpg")
    $picrechts3 = _QuickDraw_LoadTexture("./pics/" & $picr3 & ".jpg")
    $picrechts2 = _QuickDraw_LoadTexture("./pics/" & $picr2 & ".jpg")
    $piclinks = _QuickDraw_LoadTexture("./pics/" & $picl & ".jpg")
    $picrechts = _QuickDraw_LoadTexture("./pics/" & $picr & ".jpg")
    $picmitte = _QuickDraw_LoadTexture("./pics/" & $picm & ".jpg")

    [/autoit] [autoit][/autoit] [autoit]

    ;schritte berechnen
    Dim $schritt[4][3]
    ;Bild 1 zu 0
    $schritt[0][0] = ($pos[1][0] - $pos[0][0]) / $schritte
    $schritt[0][1] = ($pos[0][1] - $pos[1][1]) / $schritte
    $schritt[0][2] = ($pos[1][2] - $pos[0][2]) / $schritte

    [/autoit] [autoit][/autoit] [autoit]

    ;Bild 2 zu 1
    $schritt[1][0] = ($pos[2][0] - $pos[1][0]) / $schritte
    $schritt[1][1] = ($pos[1][1] - $pos[2][1]) / $schritte
    $schritt[1][2] = ($pos[2][2] - $pos[1][2]) / $schritte

    [/autoit] [autoit][/autoit] [autoit]

    ;Bild 3 zu 2
    $schritt[2][0] = ($pos[3][0] - $pos[2][0]) / $schritte
    $schritt[2][1] = ($pos[3][1] - $pos[2][1]) / $schritte
    $schritt[2][2] = ($pos[2][2] - $pos[3][2]) / $schritte

    [/autoit] [autoit][/autoit] [autoit]

    ;Bild 4 zu 3
    $schritt[3][0] = ($pos[4][0] - $pos[3][0]) / $schritte
    $schritt[3][1] = ($pos[4][1] - $pos[3][1]) / $schritte
    $schritt[3][2] = ($pos[3][2] - $pos[4][2]) / $schritte

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $i = 1
    for $i = 1 to $schritte

    [/autoit] [autoit][/autoit] [autoit]

    _QuickDraw_ClearBuffer(0xFF000000)
    _QuickDraw_Rect($pos[0][0], $pos[0][1], $pos[0][2], $pos[0][2], $piclinks2, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[4][0], $pos[4][1], $pos[4][2], $pos[4][2], $picrechts3, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[4][0] - $schritt[3][0] * $i, $pos[4][1] - $schritt[3][1] * $i, $pos[4][2] + $schritt[3][2] * $i, $pos[4][2] + $schritt[3][2] * $i, $picrechts2, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[1][0] - $schritt[0][0] * $i, $pos[1][1] + $schritt[0][1] * $i, $pos[1][2] - $schritt[0][2] * $i, $pos[1][2] - $schritt[0][2] * $i, $piclinks, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[3][0] - $schritt[2][0] * $i, $pos[3][1] - $schritt[2][1] * $i, $pos[3][2] + $schritt[2][2] * $i, $pos[3][2] + $schritt[2][2] * $i, $picrechts, 0xFFFFFFFF)
    _QuickDraw_Rect($pos[2][0] - $schritt[1][0] * $i, $pos[2][1] + $schritt[1][1] * $i, $pos[2][2] - $schritt[1][2] * $i, $pos[2][2] - $schritt[1][2] * $i, $picmitte, 0xFFFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    _QuickDraw_SwapBuffers()
    sleep(5)

    [/autoit] [autoit][/autoit] [autoit]

    Next

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _QuickDraw_Disable()
    Exit
    EndFunc ;==>_Exit

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • Hallo jtr1980,

    herzlich willkommen im Forum und viel Spass mit AutoIt.

    Hier kannst du dir die Hilfe herunterladen.
    Hier gibt es ein AutoIt-Tutorial: http://wiki.autoit.de/wiki/index.php/TutorialSehr hilfreich ist auch das Buch von peethebee

    und jetzt zu:

    Aber sobald ich drücke spuckt er mir meine Msgbox zum testen aus.


    nimm stattdessen

    [autoit]

    ConsoleWrite

    [/autoit]

    dann erhälst du die Info in der Scite-Konsole,

    mfg autoBert

    Einmal editiert, zuletzt von autoBert (7. Januar 2011 um 15:23)

  • Danke fürs Willkommen.
    Die Hilfen sind kein Thema aber trotzdem danke dafür.
    (Ich bin glaube ich bin jemand der die Suchfunktion von Foren kennt. ;) )
    Das

    [autoit]

    ConsoleWrite

    [/autoit]

    nützt mir nichts, weil es ja mein Problem nicht löst. (benutze lieber msgboxen)
    Das Script spuckt die koords sofort aus, obwohl die Maustaste immer noch gedrückt ist.
    Ziel ist es aber das es mir die koords erst gibt, wenn ich die taste loslasse.
    Also die koord vom Punkt wo ich sie gedrückt habe, und die koord wo ich sie loslasse.

    mfg jtr1980

  • Vllt hilft dir

    [autoit]

    _isPressed()

    [/autoit]

    weiter. Überprüfen ob geklickt > überprüft wann nciht mehr das ist dann losgelassen.

  • Hab ich ja drin und die funktioniert halt nicht.
    Kleiner Schnippsel:

    [autoit]


    $mouse_pos= _QuickDraw_GetMousePos(-1)
    $druck=_IsPressed(01,$dll)

    [/autoit][autoit][/autoit][autoit]

    If $anfangmaus = 0 And $druck = "True" Then
    $anfangmaus = $mouse_pos[0]
    $gedrueckt = 1
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If $gedrueckt = 1 And $druck = "False" Then
    $endemaus = $mouse_pos[0]
    ConsoleWrite ($anfangmaus & " bis " & $endemaus & @CRLF)
    $anfangmaus = 0
    $gedrueckt = 0
    EndIf

    [/autoit][autoit][/autoit][autoit][/autoit]

    mfg jtr1980

  • Mach es doch so.

    Spoiler anzeigen
    [autoit]

    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $vU32Dll = DllOpen("User32.dll")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(20)
    If _IsPressed("01", $vU32Dll) Then
    $aMousePos1 = MouseGetPos()
    While _IsPressed("01", $vU32Dll) And Sleep(20)
    WEnd
    $aMousePos2 = MouseGetPos()

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(64, "Mouse", "Koordinaten Punkt 1: " & $aMousePos1[0] & "|" & $aMousePos1[1] & @CRLF & "Koordinaten Punkt 2: " & $aMousePos2[0] & "|" & $aMousePos2[1])
    EndIf
    WEnd

    [/autoit]