I spent a good part of a day looking for the solution, but I could not have done it if I did not have help from other previous AutoIteers posting so in the spirit of caring is sharing , here is working code
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
$input = GUICtrlCreateInput("Command", 5, 5, 190, 17)
GUISetState(@SW_SHOW)
; trap some events not handled by main event loop
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
; Case $input ; note - I have omitted checking for change event here - done in the WM_Command Function!!
; DoCmd()
EndSwitch
WEnd
Func DoCmd()
MsgBox(0,'',"Ya ya - we are here - doing command " & guictrlread($input))
EndFunc
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0x0000FFFF)
if $nID = $input Then ; change event on input
if _IsPressed('0D') THEN
; enter was pressed, respond
DoCmd()
endif
return
endif
if _GuiCtrlGetFocus($Form1) = $input Then
; we are on the input field and no change was made
; see if the enter key was pressed
if _IsPressed('0D') THEN
; yes, it was pressed, respond
DoCmd()
endif
endif
EndFunc
Func _GuiCtrlGetFocus($GuiRef)
Local $hwnd = ControlGetHandle($GuiRef, "", ControlGetFocus($GuiRef))
Local $result = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hwnd)
Return $result[0]
EndFunc