Sign in to follow this  
Followers 0
BALA

Detecting an Enter key in an input

8 posts in this topic

I want to have something happen when an Enter key is pressed in an input. I tried having:

If _IsPressed("0D") Then ;whatever

But that would go off whenever the Enter key was pressed, regardless of if the user had the input selected. I guess what I need is something like GUICtrlRead, but will able able to detect keys pressed in it.


[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites



This should be in AutoIt1-2-3

#include <GUIConstants.au3>

GUICreate("Test", 200,100)
$Input = GUICtrlCreateEdit("",5,5,190,21, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL))

GUISetState()

While 1
    $Read = GUICtrlRead($Input)
    If StringRight($Read,2) = @CRLF Then
        $Read = StringTrimRight($Read,2)
        GUICtrlSetData($Input,$Read)
        MsgBox(0, "Test data", $Read)
    EndIf
    IF GUIGetMsg() = -3 Then Exit
WEnd

Share this post


Link to post
Share on other sites

No, combo boxes will not accept an Enter. You will need a different way to check for this. I once did a listbox like that, I hotkeyed the Enter and checked if the control and the window were both active once enter was pressed, if it was not I would unhotkey that enter and Send it. This has a downside to it, if the active window does not accept simulated keys.

Share this post


Link to post
Share on other sites

Did I miss your point (hope so) or is this what you want ?

#include <GUIConstants.au3>

$hGUI = GUICreate("", 300, 50)
$nInput = GUICtrlCreateInput("", 10, 10, 280, 21)
GUISetState()

While 1
    $iMsg = GUIGetMsg()
    
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $nInput
            WinSetTitle($hGUI, "", GUICtrlRead($nInput))
            
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

...perhaps take a look here...

In that topic it's shown how to do it with a edit-control, while BALA here has a input-control.

Also my script above shows the way of doing it with a input-control, and there's seriously nothing advanced with it...

Just simple GUIGetMsg-usage.

Share this post


Link to post
Share on other sites

there's seriously nothing advanced with it...

Just simple GUIGetMsg-usage.

I agree, this works for 99.999% of us.

eltorro

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