Script blockt Doppel-Klick auf Desktop - Warum?

  • Hallo, ich bin gerade dabei ein Programm zu basteln, allerdings wegen eines Problems, was ich vorher beheben muss noch nicht weit gekommen.

    Ich lese aktuell den Text des Steuerelementes unter dem Mauszeiger aus. Dabei möchte ich möglichst wenig Delay haben. Die Funktion habe ich soweit fertig:

    [autoit]


    #include <WinAPI.au3>
    #include <MsgBoxConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiEdit.au3>
    #NoTrayIcon

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

    $Form1_1 = GUICreate("Elemente Auslesen V1.0", 410, 800, 191, 90)
    $Input1 = GUICtrlCreateInput("", 8, 56, 193, 21)
    $Input2 = GUICtrlCreateInput("", 208, 56, 193, 21)
    $Label1 = GUICtrlCreateLabel("Aktuelles Steuerelement", 8, 8, 398, 17)
    $Label2 = GUICtrlCreateLabel("Handle", 8, 32, 38, 17)
    $Label3 = GUICtrlCreateLabel("Text", 208, 32, 25, 17)

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

    ;HotKeySet("{ESC}", "Close")
    Global $tStruct = DllStructCreate($tagPOINT)
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

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

    Opt("GUIOnEventMode", 1)

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

    While 1
    PositionCursor()
    sleep(100)
    WEnd

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

    Func Close()
    Exit
    EndFunc

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

    Func PositionCursor()
    Local $hWnd
    Position() ; Update the X and Y elements with the X and Y co-ordinates of the mouse.
    $hWnd = _WinAPI_WindowFromPoint($tStruct) ;
    _GUICtrlEdit_SetText($Input1, $hWnd)
    _GUICtrlEdit_SetText($Input2, ControlGetText ($hWnd,"",""))
    EndFunc

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

    Func Position()
    DllStructSetData($tStruct, "x", MouseGetPos(0))
    DllStructSetData($tStruct, "y", MouseGetPos(1))
    EndFunc

    [/autoit]

    Sobald ich die Sleep Pause in der Schleife, in der die Funktionen ausgeführt werden, relativ gering setze, werden Doppelklicks auf dem Desktop geblockt. Die Frage ist warum ist das so und was tue ich dagegen? Die Sleep-Dauer zu erhöhen ist nicht die Lösung, da es wohl möglich sein muss, im Interval von 100ms ein Steuerelement auslesen zu können.

    Danke für eure Hilfe.

    • Offizieller Beitrag

    Probier es so:

    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>
    #include <MsgBoxConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiEdit.au3>
    #NoTrayIcon
    $Form1_1 = GUICreate("Elemente Auslesen V1.0", 410, 800, 191, 90)
    $Input1 = GUICtrlCreateInput("", 8, 56, 193, 21)
    $Input2 = GUICtrlCreateInput("", 208, 56, 193, 21)
    $Label1 = GUICtrlCreateLabel("Aktuelles Steuerelement", 8, 8, 398, 17)
    $Label2 = GUICtrlCreateLabel("Handle", 8, 32, 38, 17)
    $Label3 = GUICtrlCreateLabel("Text", 208, 32, 25, 17)
    ;HotKeySet("{ESC}", "Close")
    Global $tStruct = DllStructCreate($tagPOINT)
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    Opt("GUIOnEventMode", 1)

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

    While 1
    PositionCursor()
    Sleep(10)
    WEnd
    Func Close()
    Exit
    EndFunc ;==>Close
    Func PositionCursor()
    Local $hWnd
    Local Static $holdWnd
    $tStruct = _WinAPI_GetMousePos()
    $hWnd = _WinAPI_WindowFromPoint($tStruct)
    If $holdWnd <> $hWnd Then ; Gui nur updaten, wenn sich das Control unter der Maus ändert
    _GUICtrlEdit_SetText($Input1, $hWnd)
    _GUICtrlEdit_SetText($Input2, _WinAPI_GetWindowText($hWnd))
    $holdWnd = $hWnd
    EndIf
    EndFunc ;==>PositionCursor

    [/autoit]

    Das Hauptproblem an deinem Script ist, das der Text der Inputs ständig neu gesetzt wird.
    Das kostet Zeit und ist unnötig, der Inputtext muss nur neu gesetzt werden, wenn sich etwa ändert.