Jump to content

textbox event on enter only works once


 Share

Recommended Posts

I have a textbox and on enter I execute a function

global $iTxt
.
.
.

$iTxt = GUICtrlCreateInput("", 48, 56, 825, 21)
while 1  ; check events here
.
.
.
  case $iTxt
     DoCmd()
wend


Function DoCmd()

    $dta = GUICtrlRead($iTxt)

endfunction

It works perfectly the first time, but when I press enter again on the textbox to redo the command, the event is not fired.  If I backspace and retype the command the event is fired

How do I get the event to work all the time without backspacing and retyping?

Edited by aiter
syntx
Link to comment
Share on other sites

  • Developers

Please post a code snippet that works and demonstrates the issue when ran, as this is looking fine to me.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 120, 64, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
        Case $GU5I_EVENT_CLOSE
            Exit

        Case $Input1
            DoCmd()
    EndSwitch
WEnd

Func DoCmd()
    MsgBox(0, '', 'test')
EndFunc   ;==>DoCmd

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 120, 64, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
        Case $GU5I_EVENT_CLOSE
            Exit

        Case $Input1
            DoCmd()
    EndSwitch
WEnd

Func DoCmd()
    MsgBox(0, '', 'test')
EndFunc   ;==>DoCmd

I get the alert once when I enter - when I enter again,  no alert.

Link to comment
Share on other sites

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

 

 

Edited by aiter
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...