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ß
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ß
Es geht, aber die MsgBox kannst du nicht direkt ausgeben, da die Auswertung von WindowsMessages nicht unterbrochen werden darf. Deshalb brauchst du Globale Hilfsvariablen:
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
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)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Do
If $currentInput <> $lastInput Then
$lastInput = $currentInput
MsgBox(0, 'Input', 'aktuell: ' & $currentInput)
EndIf
Until GUIGetMsg() = -3
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
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
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
; 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
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
Entweder du verwendest den MessageLoop Mode oder den OnEvent Mode.
Edit:
BugFix, es geht auch leichter/kürzer:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$hGui = GUICreate("Test", 250, 100, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_VISIBLE))
$idButton = GUICtrlCreateInput("foobar", 50, 50, 150)
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $idButton
Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(4096, ''Hello World!'', ''Hi!'')"')
EndSwitch
WEnd
(Auch wenn ich mir nicht komplett sicher bin, ob das funktioniert. Ist im Browser geschrieben + lange nichts mit AutoIt geschrieben.)
Hier noch eine Variante falls es dir speziell darum geht zu überprüfen ob ein Input geklickt wurde..
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
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()
while GUIGetMsg()<>$GUI_EVENT_CLOSE
local $AktivesInput=focus()
if $AktivesInput2<>$AktivesInput and $AktivesInput<>"" Then
$AktivesInput2=$AktivesInput
MsgBox("","","Input" & $AktivesInput2 & " wurde angeklickt")
EndIf
WEnd
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
wenn es dir nur um den Fokus geht ist die Variante von BugFix natürlich sauberer
BugFix, es geht auch leichter/kürzer:
Einfach kann jeder...