Jump to content

Accept Enter Key on input box


Recommended Posts

Here I have 2 input box and both can accept ENTER key from keyboard. I want to be able to allow only $input1 input box to accept the ENTER from keyboard and executes, and does nothing if i'm on other input box when I hit enter. I'm thinking of an 'If' condition somewhere but don't know what to check for. Can someone please help?

#include <GuiConstants.au3>

$gui = GUICreate("test", 300, 100)

$input1 = GUICtrlCreateInput("input test", 10, 10, 250, 30)

$input2 = GUICtrlCreateInput("another input test", 10, 40, 250, 30)

$Enter_KEY = GUICtrlCreateDummy()

Dim $Arr[1][2] = [["{ENTER}", $Enter_KEY]]

GUISetAccelerators($Arr)

GUISetState()

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Enter_KEY
    $currCtrl = ControlGetFocus($gui)

    $currVal = ControlGetText($gui, "", $currCtrl)
            MsgBox(0, "", "The input was ''" & $currVal & "''")

    EndSwitch

WEnd
Link to comment
Share on other sites

Is this what you mean?

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Enter_KEY
            $CurrCtrl = ControlGetFocus($gUi)
            If $CurrCtrl = 'Edit2' Then ContinueCase
            $currVal = ControlGetText($gUi, "", $CurrCtrl)
            MsgBox(0, GUICtrlGetHandle($input2), "The input was ''" & $currVal & "''")
    EndSwitch
WEnd
Link to comment
Share on other sites

Yes so far i think that's it. So 'Edit#' is the number of counts of input box i have correct? In my GUI i have at least 8 input boxes. Is it the matter of finding the right number of 'Edit' box?

Is this what you mean?

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Enter_KEY
            $CurrCtrl = ControlGetFocus($gUi)
            If $CurrCtrl = 'Edit2' Then ContinueCase
            $currVal = ControlGetText($gUi, "", $CurrCtrl)
            MsgBox(0, GUICtrlGetHandle($input2), "The input was ''" & $currVal & "''")
    EndSwitch
WEnd
Link to comment
Share on other sites

Yeah, I just checked the value of $CurrCtrl in the existing Msgbox. That's where I got the value. Just change the line to;

MsgBox(0, $currCtrl, "The input was ''" & $currVal & "''")
Edited by Varian
Link to comment
Share on other sites

Thank you so much for helping. I also found this helpful since i have 14 input boxes and i wanted the 12 to accept Enter key. Instead of

$CurrCtrl = 'Edit1' Or $CurrCtrl = 'Edit2'
etc.. to 12, i took a shortcut :D. Thanks everyone for helping.

Case $Enter_KEY
            $CurrCtrl = ControlGetFocus($GUI)
            If $CurrCtrl = 'Edit12' Then Call("_Ent")

Yeah, I just checked the value of $CurrCtrl in the existing Msgbox. That's where I got the value. Just change the line to;

MsgBox(0, $currCtrl, "The input was ''" & $currVal & "''")
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...