astrax Posted March 25, 2009 Share Posted March 25, 2009 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 More sharing options...
jvanegmond Posted March 25, 2009 Share Posted March 25, 2009 Old trick:http://www.autoitscript.com/forum/index.ph...c=39786&hl=May need some modification concerning the includes. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Varian Posted March 25, 2009 Share Posted March 25, 2009 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 More sharing options...
astrax Posted March 25, 2009 Author Share Posted March 25, 2009 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 More sharing options...
Varian Posted March 25, 2009 Share Posted March 25, 2009 (edited) 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 March 25, 2009 by Varian Link to comment Share on other sites More sharing options...
ResNullius Posted March 25, 2009 Share Posted March 25, 2009 @astrax,Another way: http://www.autoitscript.com/forum/index.ph...st&p=657106 Link to comment Share on other sites More sharing options...
astrax Posted March 25, 2009 Author Share Posted March 25, 2009 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 . 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now