If Input = active/clicked ?

  • Hallo, ich wollte fragen ob es möglich ist, dass, wenn man einen Input anklickt, AutoIt dann z.B: mit einer MsgBox reagieren kann?

    GUICtrlCreateInput("Input1", 8, 8, 137, 21)


    Das ist gemeint.

    Gruß

    • Offizieller Beitrag

    Es geht, aber die MsgBox kannst du nicht direkt ausgeben, da die Auswertung von WindowsMessages nicht unterbrochen werden darf. Deshalb brauchst du Globale Hilfsvariablen:

    Spoiler anzeigen
    [autoit]

    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    Global $currentInput, $lastInput

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

    GUICreate("Test")
    $cInput1 = GUICtrlCreateInput("", 10, 30, 150)
    $cInput2 = GUICtrlCreateInput("", 10, 60, 150)
    $hInput1 = GUICtrlGetHandle($cInput1)
    $hInput2 = GUICtrlGetHandle($cInput2)

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

    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

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

    Do
    If $currentInput <> $lastInput Then
    $lastInput = $currentInput
    MsgBox(0, 'Input', 'aktuell: ' & $currentInput)
    EndIf
    Until GUIGetMsg() = -3

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

    Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
    Case $hInput1, $hInput2
    Local $sID = 'Input1'
    If $iIDFrom = $cInput2 Then $sID = 'Input2'
    Switch $iCode
    Case $EN_ALIGN_LTR_EC ; Sent when the user has changed the edit control direction to left-to-right

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

    Case $EN_ALIGN_RTL_EC ; Sent when the user has changed the edit control direction to right-to-left

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

    Case $EN_CHANGE ; Sent when the user has taken an action that may have altered text in an edit control
    ConsoleWrite('Inhalt geändert: ' & $sID & @LF)
    Case $EN_ERRSPACE ; Sent when an edit control cannot allocate enough memory to meet a specific request

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

    Case $EN_HSCROLL ; Sent when the user clicks an edit control's horizontal scroll bar

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

    Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
    ConsoleWrite('Focus verloren: ' & $sID & @LF)
    Case $EN_MAXTEXT ; Sent when the current text insertion has exceeded the specified number of characters for the edit control

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

    ; This message is also sent when an edit control does not have the $ES_AUTOHSCROLL style and the number of characters to be
    ; inserted would exceed the width of the edit control.
    ; This message is also sent when an edit control does not have the $ES_AUTOVSCROLL style and the total number of lines resulting
    ; from a text insertion would exceed the height of the edit control
    Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
    ConsoleWrite('Focus erhalten: ' & $sID & @LF)
    $currentInput = $sID
    Case $EN_UPDATE ; Sent when an edit control is about to redraw itself

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

    Case $EN_VSCROLL ; Sent when the user clicks an edit control's vertical scroll bar or when the user scrolls the mouse wheel over the edit control

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

    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_COMMAND

    [/autoit]
  • Entweder du verwendest den MessageLoop Mode oder den OnEvent Mode.

    Edit:
    BugFix, es geht auch leichter/kürzer:

    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    $hGui = GUICreate("Test", 250, 100, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_VISIBLE))
    $idButton = GUICtrlCreateInput("foobar", 50, 50, 150)

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

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    Case $idButton
    Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(4096, ''Hello World!'', ''Hi!'')"')
    EndSwitch
    WEnd

    [/autoit]

    :)
    (Auch wenn ich mir nicht komplett sicher bin, ob das funktioniert. Ist im Browser geschrieben + lange nichts mit AutoIt geschrieben.)

    There's a joke that C has the speed and efficieny of assembly language combined with readability of....assembly language. In other words, it's just a glorified assembly language. - Teh Interwebz

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, you blow off your whole leg. - Bjarne Stroustrup
    Genie zu sein, bedeutet für mich, alles zu tun, was ich will. - Klaus Kinski

    2 Mal editiert, zuletzt von PainTain (25. August 2014 um 16:24)

  • Hier noch eine Variante falls es dir speziell darum geht zu überprüfen ob ein Input geklickt wurde..

    Spoiler anzeigen
    [autoit]


    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <Misc.au3>

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

    Global $inp1, $inp2, $inp3
    $AktivesInput2=""
    $form=GUICreate(" My GUI", 320, 120)
    $inp1 = GUICtrlCreateInput("", 10, 5, 300, 20)
    $inp2 = GUICtrlCreateInput("", 10, 35, 300, 20)
    $inp3 = GUICtrlCreateInput("", 10, 65, 300, 20)
    GUISetState()

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

    while GUIGetMsg()<>$GUI_EVENT_CLOSE
    local $AktivesInput=focus()
    if $AktivesInput2<>$AktivesInput and $AktivesInput<>"" Then
    $AktivesInput2=$AktivesInput
    MsgBox("","","Input" & $AktivesInput2 & " wurde angeklickt")
    EndIf
    WEnd

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


    func Focus()
    local $arr=GUIGetCursorInfo($form), $focus=""
    if $arr[2] Then
    switch $arr[4]
    Case $inp1
    $focus="1"
    Case $inp2
    $focus="2"
    Case $inp3
    $focus="3"
    EndSwitch
    endif
    return $focus
    EndFunc

    [/autoit]

    wenn es dir nur um den Fokus geht ist die Variante von BugFix natürlich sauberer  :)

    Einmal editiert, zuletzt von Markus123 (25. August 2014 um 17:10)