Jump to content

Enter Key in a GUICtrlCreateInput box


Lakes
 Share

Recommended Posts

$Form1 = GUICreate("Meetcam Text to Speech", 421, 68, 190, 188)
GUISetBkColor(0x000080)
$InputBox = GUICtrlCreateInput("!s Type anything here", 8, 16, 313, 28, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$SEND = GUICtrlCreateButton("SEND", 328, 16, 73, 30)

I can use the send button fine, but I also want to type in the text and send it with the Enter Key.

How can I make this send the text when the Enter Key is pressed?

If I try to use Case $Enter = _IsPressed("0D", $dll) that does not work...

Thanks!

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

$Form1 = GUICreate("Meetcam Text to Speech", 421, 68, 190, 188)
GUISetBkColor(0x000080)
$InputBox = GUICtrlCreateInput("!s Type anything here", 8, 16, 313, 28, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$SEND = GUICtrlCreateButton("SEND", 328, 16, 73, 30)

I can use the send button fine, but I also want to type in the text and send it with the Enter Key.

How can I make this send the text when the Enter Key is pressed?

If I try to use Case $Enter = _IsPressed("0D", $dll) that does not work...

Thanks!

$Form1 = GUICreate("Meetcam Text to Speech", 421, 68, 190, 188)
GUISetBkColor(0x000080)
$InputBox = GUICtrlCreateInput("!s Type anything here", 8, 16, 313, 28, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$SEND = GUICtrlCreateButton("SEND", 328, 16, 73, 30)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

My feeble attempt

#include <GUIConstants.au3>
$Form1 = GUICreate("Meetcam Text to Speech", 421, 68, 190, 188)
GUISetBkColor(0x000080)
$InputBox = GUICtrlCreateInput("!s Type anything here", 8, 16, 313, 28, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$SEND = GUICtrlCreateButton("SEND", 328, 16, 73, 30)
GUISetState (@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    If $msg = $SEND Then
        msgbox(0,"You typed",GUICtrlRead($InputBox))
        EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

$Form1 = GUICreate("Meetcam Text to Speech", 421, 68, 190, 188)
GUISetBkColor(0x000080)
$InputBox = GUICtrlCreateInput("!s Type anything here", 8, 16, 313, 28, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$SEND = GUICtrlCreateButton("SEND", 328, 16, 73, 30)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

My feeble attempt

#include <GUIConstants.au3>
$Form1 = GUICreate("Meetcam Text to Speech", 421, 68, 190, 188)
GUISetBkColor(0x000080)
$InputBox = GUICtrlCreateInput("!s Type anything here", 8, 16, 313, 28, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$SEND = GUICtrlCreateButton("SEND", 328, 16, 73, 30)
GUISetState (@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    If $msg = $SEND Then
        msgbox(0,"You typed",GUICtrlRead($InputBox))
        EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
$BS_DEFPUSHBUTTON is the way to go, but it's a style, not a state, so the setstate won't work. just add it as a style in your GuiCtrlCreateButton() line. then when enter is pressed in the input box it will be sent to the button; as long as you don't have $ES_WANTRETURN style on your input/edit
Link to comment
Share on other sites

$BS_DEFPUSHBUTTON is the way to go, but it's a style, not a state, so the setstate won't work. just add it as a style in your GuiCtrlCreateButton() line. then when enter is pressed in the input box it will be sent to the button; as long as you don't have $ES_WANTRETURN style on your input/edit

better re-read the help file for GuiCtrlSetState, scroll down you'll find $GUI_DEFBUTTON Control will be set as the default button on the window

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

better re-read the help file for GuiCtrlSetState, scroll down you'll find $GUI_DEFBUTTON Control will be set as the default button on the window

$GUI_DEFBUTTON is a state, but that's not what i was talking about, i was talking about the style $BS_DEFPUSHBUTTON that could be added to set it as default without the extra line... but thanks :o

***edit***

re-reading this today, it looks to me like i may have appeared to take offense at your comment gary. i just wanted to make sure you know that wasn't the case; your advice is always appreciated. I was just trying to point out that we were talking about 2 different possible solutions.

Edited by cameronsdad
Link to comment
Share on other sites

$GUI_DEFBUTTON is a state, but that's not what i was talking about, i was talking about the style $BS_DEFPUSHBUTTON that could be added to set it as default without the extra line... but thanks :o

Thanks, but this only works after I have pressed the send button, typing text into the input box and pressing enter does not work.

Heres the line now..

$InputBox = GUICtrlCreateInput("!s Type anything here", 8, 16, 313, 28, -1, $BS_DEFPUSHBUTTON )

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Thanks, but this only works after I have pressed the send button, typing text into the input box and pressing enter does not work.

Heres the line now..

$InputBox = GUICtrlCreateInput("!s Type anything here", 8, 16, 313, 28, -1, $BS_DEFPUSHBUTTON )

Both ways should work the same

#include <GUIConstants.au3>

GUICreate(" My GUI", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
GUICtrlCreateInput("", 10, 35, 300, 20)  ; will not accept drag&drop files
$btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)
GUICtrlSetState($btn, $GUI_DEFBUTTON)
$another = GUICtrlCreateButton("another", 120, 75, 60, 20)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
 $msg = GUIGetMsg()
 Select
  Case $msg = $btn
   GUIDelete()
   MsgBox(0, "Default Button", "Pushed")
   ExitLoop
 EndSelect
WEnd

#include <GUIConstants.au3>

GUICreate(" My GUI 2", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
GUICtrlCreateInput("", 10, 35, 300, 20)  ; will not accept drag&drop files
$btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20, $BS_DEFPUSHBUTTON)
$another = GUICtrlCreateButton("another", 120, 75, 60, 20)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
 $msg = GUIGetMsg()
 Select
  Case $msg = $btn
   GUIDelete()
   MsgBox(0, "Default Button", "Pushed")
   ExitLoop
 EndSelect
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Both ways should work the same

#include <GUIConstants.au3>

GUICreate(" My GUI 2", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
GUICtrlCreateInput("", 10, 35, 300, 20) ; will not accept drag&drop files
$btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20, $BS_DEFPUSHBUTTON)
$another = GUICtrlCreateButton("another", 120, 75, 60, 20)
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
 $msg = GUIGetMsg()
 Select
  Case $msg = $btn
   GUIDelete()
   MsgBox(0, "Default Button", "Pushed")
   ExitLoop
 EndSelect
WEnd
Thanks for the examples!, I made a silly mistake, I was applying the style to the input box instead of the Button, Doh! :o

Thanks for the help!

2015 - Still no flying cars, instead blankets with sleeves.

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...