Sign in to follow this  
Followers 0
sugi

Gui. Catch Enter Key In An Input Field

9 posts in this topic

How can I catch when someone presses the enter key while being in an input box?

I want to run the commands associated to $button_1 when the user is pressing enter in the input box ($input_1). Setting a notify doesn't seem to work.

Local $button_1, $input_1, $button_2, $button_3, $list_2, $list_3, $button_4, $msg
    GuiCreate("CG-IT Admin-GUI", 411,482)
    $button_1 = GUISetControl("button", "Search", 140,10, 50,20)
    GUISetControlNotify()
    $input_1 = GUISetControl("input", "Computername", 10,10, 120,20)
    GUISetControlNotify()
    $GUIComputerList = GUISetControl("list", "Computerlists", 10,40, 120,430)
    GUISetControlNotify()
    $button_2 = GUISetControl("button", "Update DB", 200,10, 60,20)
    GUISetControlNotify()
    $button_3 = GUISetControl("button", "Exit", 370,10, 30,20)
    GUISetControlNotify()
    $list_2 = GUISetControl("list", "Commands", 140,40, 130,430)
    GUISetControlNotify()
    $list_3 = GUISetControl("list", "Directories", 280,40, 120,430)
    GUISetControlNotify()
;   $button_4 = GUISetControl("button", "Help / Info", 270,10, 60,20)
;   GUISetControlNotify()
    
    GuiShow()

    FilterComputers("")
    While 1
  $msg = GuiMsg()
  Select
     Case $msg < 1
    Exit(0)
     Case $msg = $button_1
    FilterComputers(GUIRead($input_1))
     Case $msg = $input_1
    FilterComputers(GUIRead($input_1))
     Case $msg = $GUIComputerList
    GUIWrite($input_1, 0, GUIRead($GUIComputerList))
     Case $msg = $button_2
    UpdateDomains()
    UpdateComputers()
     Case $msg = $button_3
    Exit(0)
     Case $msg = $list_2
     ;;;
     Case $msg = $list_3
     ;;;
;    Case $msg = $button_4
;    ShowHelp()
  EndSelect
    WEnd

Share this post


Link to post
Share on other sites



The main problem I see is that you aren't storing the notify anywhere. You can't check the return of GuiMsg(0) with the buttons, but with the notify. Do something like this instead:

GuiCreate("box", 200, 200)
$input1 = GuiSetControl("input", "stuff", 0, 0, 100, 20)
$input1_notify = GuiSetControlNotify()

GuiShow()

While 1
  $msg = GuiMsg(0)
  If $msg = -3 Then Exit;user hit exit button on top
  If $msg = $input1_notify Then
   ;handle the input notification here
  EndIf
WEnd

Please see the AutoIt manual entry for GuiMsg() for more info.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

I was storing the control numbers that are returned from GUISetControl(). According to the help file, GUISetControlNotify returns the same value (the control number), so $input_1 and $input_1_notify should be the same.

I noted where the error seems to be: after entering something in the input box and pressing enter, nothing happens. But as soon as I click on one of the buttons (no matter which one), the commands assigned to $input_1 are run. So for me this looks like AutoIt doesn't return from GUIMsg() when a Message from an input field comes in.

Share this post


Link to post
Share on other sites

You are correct. I played around a bit further myself, and at this time you cannot get a notify message for a change of text on an input field. In a future release perhaps we will be able to test for a change of text or the enter key pressed. I found that although the notify itself works, it will not be passed to any handeling you have written until a button is pressed. When this occurs, the input notify is passed through GuiMsg(0), but the button press is lost. I discovered in another thread that this is a bug and should eventually be addressed.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This is not a bug but limitation. Autoit can't handle two subsequental messages. You must decide which message you want. But I think you can to bypass this problem: just add hotkey that will capture Enter key and add needed code into it's handler.

HotkeySet("{ENTER}", "EnterKey") 

;....

Func EnterKey()
    MsgBox (262144, "title", "Enter Pressed")
EndFunc

Of course, you must use GUIMsg(0) to get it work.

Edited by Kot

Share this post


Link to post
Share on other sites

@sugi

I think you will have a better behavior with the next version of GUI 102.23

THanks for helping to find the bug

:D

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

How can I find out what release of AutoIt 3.0.102 I'm using? The help file doesn't go into more detail than 3.0.102 and the "version" information from the AutoIt3.exe file only says 3.0.102.0. Also, how would I obtain the latest release of AutoIt GUI? Thanks!

I guess I should take a look at the timestamp for files in the ~/unstable dir first, 'eh? Although I am still wondering how I find my installed version number.

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Jon doesn't use the fourth number in the version syntax. It might be worth looking into using the 4th parameter during testing to differentiate between those builds, but that's just one more thing to forget to do when posting a new build (Of either sort, either forgetting to update that number when releasing a new unstable or forgetting to reset it to 0 when releasing a new build).

Also, it was mentioned using md5 sums in order to distinguish versions. But until something is done, there isn't any simple, reliable way to see if you have unstable 3.0.102 3rd release or 6th release or whatever.

Share this post


Link to post
Share on other sites

How can I find out what release of AutoIt 3.0.102 I'm using?  The help file doesn't go into more detail than 3.0.102 and the "version" information from the AutoIt3.exe file only says 3.0.102.0.  Also, how would I obtain the latest release of AutoIt GUI?  Thanks!

I guess I should take a look at the timestamp for files in the ~/unstable dir first, 'eh?  Although I am still wondering how I find my installed version number.

The official beta is under unstable and until now is from gui point of view what i number 102.22. Not a lot of change in the incoming 102.23 so you can work with this version.

You have to be carefull of download problem if you are behind a proxy.

I always add to the "http:..." ?new=X.

X changing when I do a new download. :D

Share this post


Link to post
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
Sign in to follow this  
Followers 0