Jump to content
Sign in to follow this  
Gideon

input problem

Recommended Posts

Gideon

Hello,

When the user types in something and press enter it says: "you typed in:" & $something. and it shows the button.

When you press enter again it doesn't work anymore, I realised that it's normal, because you didn't edit it.

But I like the user to press enter every time.

Is there a way to force that?

ps, sorry for my poor english

[sOLVED]:idea:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>


$gui = GUICreate( "test", 200, 200)
$inp = GUICtrlCreateInput("", 10, 10,100,20)
$but = GUICtrlCreateButton("clear text", 120, 10)
GUICtrlSetState($but, $GUI_HIDE)
GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $inp
            MsgBox(0,"test", "You typed in" & guictrlread($inp))
            GUICtrlSetState($but, $GUI_SHOW)
        Case $msg = $but
            GUICtrlSetData($inp, "")
            GUICtrlSetState($but, $GUI_HIDE)
    EndSelect
    
WEnd
GUIDelete()
Edited by Gideon

Many times you need to think like hobby-bob:')

Share this post


Link to post
Share on other sites
Melba23

Gideon,

It is not a bug. :idea:

To get a message sent from an Input when you press Enter, the text within it needs to have changed (to go all geeky for a moment, it needs to have received an EN_CHANGE mesage). So if you press Enter before the text is changed, you do not get a message and so you do not fire the code. That is why nothing happens if you press Enter immediately the script starts - nothing in the input = no change = no message.

I hope that explains what is going on. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Gideon

Gideon,

It is not a bug. :idea:

To get a message sent from an Input when you press Enter, the text within it needs to have changed (to go all geeky for a moment, it needs to have received an EN_CHANGE mesage). So if you press Enter before the text is changed, you do not get a message and so you do not fire the code. That is why nothing happens if you press Enter immediately the script starts - nothing in the input = no change = no message.

I hope that explains what is going on. :)

M23

I already realised that^^, although, thanks for the reply:)

How can you say EN_CHANGE = true everytime it's not true?

Edited by Gideon

Many times you need to think like hobby-bob:')

Share this post


Link to post
Share on other sites
Melba23

Gideon,

If you edit your question while I am answering the original version, the response is unlikely to be as helpful as you wanted. :)

Anyway, you do not need to send a message, you can do it this way:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

$gui = GUICreate( "test", 200, 200)
$inp = GUICtrlCreateInput("", 10, 10,100,20)
$but = GUICtrlCreateButton("clear text", 120, 10)
$hDummy = GUICtrlCreateDummy()
GUICtrlSetState($but, $GUI_HIDE)
GUISetState(@SW_SHOW)

; Set accelerator for Enter to action the Dummy code
Dim $AccelKeys[1][2]=[["{ENTER}", $hDummy]]
GUISetAccelerators($AccelKeys)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $hDummy
            ; Check input has focus
            If _WinAPI_GetFocus() = GUICtrlGetHandle($inp) Then
                $sText = GUICtrlRead($inp)
                MsgBox(0,"test", "You typed in " & $sText)
                GUICtrlSetState($but, $GUI_SHOW)
            EndIf
        Case $msg = $but
            GUICtrlSetData($inp, "")
            GUICtrlSetState($but, $GUI_HIDE)
    EndSelect

WEnd
GUIDelete()

By setting the accelerator, we run the $hDummy code when we press Enter. But we need to check if the Input has focus so that we do not fire the code every time we press Enter, only when the Input is active.

I hope that helps. :idea:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Gideon

Gideon,

If you edit your question while I am answering the original version, the response is unlikely to be as helpful as you wanted. :)

Anyway, you do not need to send a message, you can do it this way:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

$gui = GUICreate( "test", 200, 200)
$inp = GUICtrlCreateInput("", 10, 10,100,20)
$but = GUICtrlCreateButton("clear text", 120, 10)
$hDummy = GUICtrlCreateDummy()
GUICtrlSetState($but, $GUI_HIDE)
GUISetState(@SW_SHOW)

; Set accelerator for Enter to action the Dummy code
Dim $AccelKeys[1][2]=[["{ENTER}", $hDummy]]
GUISetAccelerators($AccelKeys)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $hDummy
            ; Check input has focus
            If _WinAPI_GetFocus() = GUICtrlGetHandle($inp) Then
                $sText = GUICtrlRead($inp)
                MsgBox(0,"test", "You typed in " & $sText)
                GUICtrlSetState($but, $GUI_SHOW)
            EndIf
        Case $msg = $but
            GUICtrlSetData($inp, "")
            GUICtrlSetState($but, $GUI_HIDE)
    EndSelect

WEnd
GUIDelete()

By setting the accelerator, we run the $hDummy code when we press Enter. But we need to check if the Input has focus so that we do not fire the code every time we press Enter, only when the Input is active.

I hope that helps. :idea:

M23

That helps me with my script:) very nice:D

Thanks!


Many times you need to think like hobby-bob:')

Share this post


Link to post
Share on other sites
Melba23

Gideon,

Glad I could help. :idea:

When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Gideon

Oke^^


Many times you need to think like hobby-bob:')

Share this post


Link to post
Share on other sites
Gideon

Oke, now I have another problem with a gui, just like that.

When I want the input only gives a message sent from an Input, and press enter, it presses the last clicked button too:(

So I made a button next to it, but the user thinks he can press enter to, but then it presses the last clicked button.

How can I fix this too?

Edit: I can only fix it, but with the possibility to buttonbash:')

Edited by Gideon

Many times you need to think like hobby-bob:')

Share this post


Link to post
Share on other sites
Melba23

Gideon,

If you do not post the code, it is very difficult to offer any help. :idea:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
GEOSoft

Gideon,

If you do not post the code, it is very difficult to offer any help. :idea:

M23

Not difficult at all. Just make sure your Crystal Scripalyzer has been recently polished and then look at the script on his computer. It should point you to the exact line which in this case is 2589674

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Melba23

George,

It is packed and in my suitcase ready to go on holiday with me tomorrow. :idea: That is why I need the code in this case.

Although I did get the initial impression that the error was closer to Line 3296 than your suggestion. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Gideon

hmm... oke, this is my code now.

When I posted it here, it didn't fit into the iframe

attach.au3

Edited by Gideon

Many times you need to think like hobby-bob:')

Share this post


Link to post
Share on other sites
Melba23

Gideon,

As I suspected, you are colouring buttons.

$ok = GUICtrlCreateButton("OK", 10, 100)
GUICtrlSetColor(-1, 0x000000)

This is a known bug (#376) where coloured buttons react to the "Enter" key.

Solution: Do not colour the button! :idea:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Gideon

Aha, but I don't want to color buttons.

But.. it is a must when you define defcolor, I don't want to put all the buttons above the defcolor, because the script will be unreadable (for me).

Although, if that's the problem, I will use the buttonbash-solution.

Thanks for the info:)

Or, now I read about $BS_DEFPUSHBUTTON, maybe that's the solution.

Or not, then the buttonbash will rule again:')

It would be great if there was a $BS_NOCOLOR or a GUICtrlSetDefColor ( deftextcolor [, winhandle][,$UNSET_DEFCOLOR = False] ).

Can I report that as an idea somewhere(if that's possible)?

Edited by Gideon

Many times you need to think like hobby-bob:')

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  

×