yutt Posted September 7, 2005 Share Posted September 7, 2005 (edited) This should be simple to do, but I'm not having any luck finding a way. My script includes an input box (the GUICtrlCreateInput type). I want an event to trigger when the user hits the Enter key while the input box has focus. It's for a chat client I am trying, so the user will type their message and hit Enter to send it. Edited September 7, 2005 by yutt It is a waste of energy to be angry with a man who behaves badly, just as it is to be angry with a car that won't go. - Bertrand Russell Link to comment Share on other sites More sharing options...
ning Posted September 7, 2005 Share Posted September 7, 2005 You can do this by creating a button that has the $BS_DEFPUSHBUTTON style. This will make it the default button on the window, and pressing ENTER anywhere will have the effect of clicking it. From the help, Creates a push button with a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely option, or default.If you don't want the users to see the button, I guess you can either set it hidden or out of the window bounds.hope that helpsben Link to comment Share on other sites More sharing options...
seandisanti Posted September 7, 2005 Share Posted September 7, 2005 This should be simple to do, but I'm not having any luck finding a way. My script includes an input box (the GUICtrlCreateInput type). I want an event to trigger when the user hit the Enter key while the input box has focus.It's for a chat client I am trying, so the user will type their message and hit Enter to send it.<{POST_SNAPBACK}>few ways to do this... you could use msgloop mode and if $msg = $input and _IsPressed(xx) (xx is the hex number code for enter) then ...or you could:HotKeySet("{ENTER}","Shenanigans") while 1 ;other code sleep(100) wend Func Shenanigans() $a = ControlGetFocus("Untitled - Notepad") if $a = controlid of inputbox here then ;more code EndIf EndFunc Link to comment Share on other sites More sharing options...
Raindancer Posted September 7, 2005 Share Posted September 7, 2005 Define the Button to Send with the Style: $BS_DEFPUSHBUTTON If the User presses Enter the "Send" Button gets Triggered... Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer Link to comment Share on other sites More sharing options...
Raindancer Posted September 7, 2005 Share Posted September 7, 2005 Everyone trying to help him... Nice Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer Link to comment Share on other sites More sharing options...
yutt Posted September 7, 2005 Author Share Posted September 7, 2005 That should work fine, though not exactly what I had in mind. Is there a way to check which element has focus? Wow, this community is pretty amazing. Thanks everyone! It is a waste of energy to be angry with a man who behaves badly, just as it is to be angry with a car that won't go. - Bertrand Russell Link to comment Share on other sites More sharing options...
Raindancer Posted September 7, 2005 Share Posted September 7, 2005 Look at this UDF: http://www.autoitscript.com/forum/index.php?showtopic=14979 Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer Link to comment Share on other sites More sharing options...
Valuater Posted September 7, 2005 Share Posted September 7, 2005 here is an example using both ideas focus and default button expandcollapse popup#include <GuiConstants.au3> Dim $stop = 0, $go = 0, $time, $t, $move GuiCreate("The W A I T E R ", 365, 316,(@DesktopWidth-392)/2, (@DesktopHeight-316)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $input1 = GuiCtrlCreateInput("wait time", 130, 85, 55, 22) GUICtrlSetState( -1, $GUI_FOCUS) $label1 = GuiCtrlCreateLabel("Please type in a *wait* time for the function ( in seconds)", 20, 150, 340, 80) $startbutton = GuiCtrlCreateButton("Start", 130, 115, 96, 23) GUICtrlSetState( -1, $GUI_DEFBUTTON) $stopbutton = GuiCtrlCreateButton("Stop", 249, 115, 96, 23) $progress = GUICtrlCreateProgress( 20, 116, 96, 20) GUISetState() ;Set on event-- does not use GUIGetMessage() Opt("GUIOnEventMode", 1) ; Change to OnEvent mode GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlSetOnEvent($startbutton, "startit") GUICtrlSetOnEvent($stopbutton, "stopit") While 1 If $go = 1 Then GUICtrlSetState( $input1, $GUI_DISABLE) $t = $t +1 $move = $move + 10 GUICtrlSetData($progress, $move) If $t = 11 then $go = 0 $t = 0 $move = 0 GUICtrlSetData($progress, 0) GUICtrlSetState( $input1, $GUI_ENABLE) GUICtrlSetData($label1, " The wait is over") EndIf Sleep($time) EndIf If $stop = 1 Then MsgBox(0, "Cancelled", "Wait was cancelled...", 2) GUICtrlSetData($progress, 0) GUICtrlSetState( $input1, $GUI_ENABLE) $stop = 0 $go = 0 $t = 0 $move = 0 EndIf If $t <> 0 Then GUICtrlSetData($label1, " The Program is still running, " & $move & "%" ) Else Sleep(300) GUICtrlSetData($label1, "Please type in a *wait* time for the function ( in seconds)") EndIf ;Sleep(5) WEnd Func stopit() $stop = 1 EndFunc Func startit() $go = 1 $inputread = GUICtrlRead($input1) $time = $inputread * 90 Endfunc Func CLOSEClicked() MsgBox(0, "Close Program", "You clicked CLOSE!" & @CRLF & "Now Exiting... The W A I T E R", 3) Exit EndFunc hope it helps 8) 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