Sign in to follow this  
Followers 0
DW1

Pressing enter on edit box

8 posts in this topic

I would like for a user to be able to click on an edit, type something, and press enter to "do" the action instead of having to click a button

How would I do this?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <GUIConstants.au3>

$GUI = GUICreate("", 162, 96, -1, -1)
$Input = GUICtrlCreateInput("Type hello then hit enter!", 8, 8, 145, 21)
$Send = GUICtrlCreateButton("&Send", 32, 40, 89, 41, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Input
            If GuiCtrlRead($Input) = "Hello" Then
                MsgBox(4096, "Hello!", "You pressed the enter key!")
            EndIf
        Case $Send
            If GuiCtrlRead($Input) = "Hello" Then
                MsgBox(4096, "Hello!", "You pressed the send key!")
            EndIf
    EndSwitch
WEnd

That's a better example.

-James

Edited by NeoTroniX

Share this post


Link to post
Share on other sites

That doesn't work, I don't have to press enter. I can just click on the edit.

Any way to make sure that only ENTER triggers the event?

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

$GUI = GUICreate("", 161, 37, -1, -1)
$Input = GUICtrlCreateInput("Type hello then hit enter!", 8, 8, 145, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Input
            If GuiCtrlRead($Input) = "Hello" Then
                MsgBox(4096, "Hello!", "You pressed the enter key!")
            EndIf
    EndSwitch
WEnd

Modified NeoTroniX's example. Is this more like what you want?

Share this post


Link to post
Share on other sites

This is more what I needed:

DUH!! to me, I found this in the FAQ sticky

HotKeySet("{ENTER}", "catchguikey")
;
;REST OF CODE HERE
;
;
Func catchguikey()
    Local $opt = Opt("WinTitleMatchMode", 4)
    If WinGetHandle("active") = $DB Then
        If @HotKeyPressed = "{ENTER}" Then
            ;Do something here
           _IENavigate($oIE, GUICtrlRead( $manualaddy ), 0)
        EndIf
    Else
        HotKeySet(@HotKeyPressed)
        Send(@HotKeyPressed)
        HotKeySet(@HotKeyPressed, "catchguikey")
    EndIf
    Opt("WinTitleMatchMode", $opt)
EndFunc

Share this post


Link to post
Share on other sites

sort of, your way will be triggered on a mouse click to the edit box as well as pressing enter, where as the one I used is ONLY for pressing enter

Also I changed the code a bit so that the proper window and the proper control must be selected.

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