Mouseclick Counter Problem

  • Mein bisheriger Code :

    Spoiler anzeigen
    [autoit]


    #include <Misc.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    Global $Left = 0
    $Form1 = GUICreate("Form1", 272, 100, 192, 124)
    $Label1 = GUICtrlCreateLabel("LeftClicks :", 24, 48, 56, 17)
    $Label2 = GUICtrlCreateLabel($Left, 96, 48, 50, 17)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case _IsPressed("01")
    Left()
    EndSwitch
    WEnd

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

    Func Left()
    While 1
    If _IsPressed("01") Then
    $Left += 1
    GUICtrlSetData($Label2, $Left)
    EndIf
    WEnd
    EndFunc ;==>Left

    [/autoit]

    Probelm : Es funktioniert eigentlich das einzige Problem ist ,dass er auch zählt wenn man die Maus gedrückt hält ,wäre nett wenn jemand eine Antwort für mich hat. :)
    Es ist sicher nicht so schwer aber ich bin erst neu in der "AuoIT-Szene" und komme einfach nicht drauf.

    Edit Oscar: AutoI-Quellcode formatiert und in AutoIt- und Spoiler-Tags gesetzt. Bitte beim einfügen von Scripten immer auf die Quellcode-Ansicht umschalten. Im Editor-Modus wird das Script verhunzt.

    Einmal editiert, zuletzt von Oscar (5. August 2013 um 19:08)

    • Offizieller Beitrag

    Dein Script kann man ziemlich kürzen (_IsPressed und die Funktion sind überflüssig):

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>

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

    #region ### START Koda GUI section ### Form=
    Global $Left = 0
    $Form1 = GUICreate("Form1", 272, 100, 192, 124)
    $Label1 = GUICtrlCreateLabel("LeftClicks:", 24, 48, 156, 17)
    $Label2 = GUICtrlCreateLabel($Left, 96, 48, 50, 17)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $GUI_EVENT_PRIMARYUP
    $Left += 1
    GUICtrlSetData($Label2, $Left)
    EndSwitch
    WEnd

    [/autoit]
  • Oscar :
    ... Nur das sein ClickCounter mittels _IsPressed Systemweit agiert, deiner nur Fensterweit.
    Mit _IsPressed sähe das so aus:

    Spoiler anzeigen
    [autoit]


    #include <Misc.au3>

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

    Global $iLeft = 0
    $hWnd = GUICreate("MouseCounter", 272, 100, 192, 124)
    $cClickLabel = GUICtrlCreateLabel("LeftClicks :", 24, 48, 56, 17)
    $cClickCounter = GUICtrlCreateLabel($iLeft, 96, 48, 50, 17)
    GUISetState()

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

    $hUser32 = DllOpen("user32.dll")

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

    While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
    Case -3
    Exit
    EndSwitch
    If _IsPressed("01", $hUser32) Then
    $iLeft += 1
    GUICtrlSetData($cClickCounter, $iLeft)
    Do
    Sleep(20)
    Until Not _IsPressed("01", $hUser32)
    EndIf
    WEnd

    [/autoit]

    Wichtig sind diese 3 Zeilen:

    [autoit]


    Do
    Sleep(20)
    Until Not _IsPressed("01", $hUser32)

    [/autoit]

    Tue solange Sleep(20) bis die Linke Maustaste nicht mehr gedrückt ist

    So far,

    chess