merriman Posted July 15, 2006 Share Posted July 15, 2006 In AutoIt Help it states When a control is clicked or *changes* a control event is sent. The event is sent to the function defined with GUICtrlSetOnEvent. Inside the user defined function @GUI_CTRLID is set to the controlID that was returned when the control was created with GUICtrlCreate. I am trying to pick up control events from a Edit control such has key presses, however, the function specified in GUICtrlSetOnEvent ($Edit_1, "EditCltEvent" ) never gets called. #include <GuiConstants.au3> GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("", 80, 50, 270, 170) GUICtrlSetOnEvent ($Edit_1, "EditCltEvent" ) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit Func EditCltEvent() MsgBox(0, "", "Event Received" & @GUI_CTRLID ) EndFunc Is what I am trying to do possible ?. Would appreciate some advice Best Regards Merriman Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Share Posted July 15, 2006 (edited) try GUIOnEventMode in the help file expandcollapse popup#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $test = GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("", 80, 50, 270, 170) GUICtrlSetOnEvent ($Edit_1, "EditCltEvent" ) GuiSetState() GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $ok1 = GUICtrlCreateButton ("OK", 10, 30, 50) GUICtrlSetOnEvent(-1, "OKPressed") $cancel1 = GUICtrlCreateButton ( "Cancel", 50, -1) GUICtrlSetOnEvent(-1, "CancelPressed") GUISetState(@SW_SHOW) ; Just idle around While 1 Sleep(10) Wend ; END Func OKPressed() MsgBox(0, "OK Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE) EndFunc Func CancelPressed() MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE) EndFunc Func SpecialEvents() Select Case @GUI_CTRLID = $GUI_EVENT_CLOSE MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) Exit Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) Case @GUI_CTRLID = $GUI_EVENT_RESTORE MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) EndSelect EndFunc Func EditCltEvent() MsgBox(0, "", "Event Received" & @GUI_CTRLID ) EndFunc edit - added some code - not tested but should get you on your way edit - fixed some spacing Edited July 15, 2006 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 Must not use GUIGetMsg() with GUIOnEventMode keep in mind. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
merriman Posted July 15, 2006 Author Share Posted July 15, 2006 Thanks for your reply guys. Ive tried what you suggested, but it only seems to work on button clicks. Best Regards Merriman Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Share Posted July 15, 2006 Thanks for your reply guys. Ive tried what you suggested, but it only seems to work on button clicks.try the help file for GUICtrlRead 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Nomad Posted July 15, 2006 Share Posted July 15, 2006 Thanks for your reply guys. I've tried what you suggested, but it only seems to work on button clicks.Could you be more specific? What do you mean?Nomad Link to comment Share on other sites More sharing options...
merriman Posted July 15, 2006 Author Share Posted July 15, 2006 Could you be more specific? What do you mean?Nomad A clicked button appears to be the only control that generates an event. A Edit Control does not appear to generate any event. Best Regards Merriman Link to comment Share on other sites More sharing options...
Nomad Posted July 15, 2006 Share Posted July 15, 2006 (edited) A clicked button appears to be the only control that generates an event. A Edit Control does not appear to generate any event. I've never used Edit controls, so I can't vouche for them. But I've used Listviews, Treeviews, Lists, Checkboxs, Combos, Radios, and Tabs, and they've all triggered events. I've even used labels to trigger events like this. Either you can't do it with Edits, which I doubt, or you're doing something wrong. Posting your current script would help. Edited July 15, 2006 by Nomad Link to comment Share on other sites More sharing options...
merriman Posted July 15, 2006 Author Share Posted July 15, 2006 I've never used Edit controls, so I can't vouche for them. But I've used Listviews, Treeviews, Lists, Checkboxs, Combos, Radios, and Tabs, and they've all triggered events. I've even used labels to trigger events like this. Either you can't do it with Edits, which I doubt, or you're doing something wrong. Posting your current script would help. #include <GuiConstants.au3> Opt("GUIOnEventMode", 1) GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("", 80, 50, 270, 170) GUICtrlSetOnEvent ($Edit_1, "EditCltEvent" ) GuiSetState() While 1 Sleep(10) Wend Exit Func EditCltEvent() MsgBox(0, "", "Event Received" & @GUI_CTRLID ) EndFunc Best Regards Merriman Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Share Posted July 15, 2006 A clicked button appears to be the only control that generates an event. A Edit Control does not appear to generate any event.What do you want to trigger the event? 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Nomad Posted July 15, 2006 Share Posted July 15, 2006 (edited) What exactly are you wanting it to do? The way it is right now, there's no event to trigger. Now if you did a drag and drop to the control, then that would be an event which would trigger. Simply clicking on the edit control shouldn't trigger anything other than giving the control focus to allow input. Edited July 15, 2006 by Nomad Link to comment Share on other sites More sharing options...
merriman Posted July 15, 2006 Author Share Posted July 15, 2006 What exactly are you wanting it to do? The way it is right now, there's no event to trigger. Now if you did a drag and drop to the control, then that would be an event which would trigger. Simply clicking on the edit control shouldn't trigger anything other than giving the control focus to allow input.Would simply typing something into the edit control trigger an event, I want to count the number characters typed into the control as the user types them, and warn the user when they are approaching the maximum number of characters allowed Best Regards Merriman Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Share Posted July 15, 2006 (edited) Would simply typing something into the edit control trigger an event, I want to count the number characters typed into the control as the user types them, and warn the user when they are approaching the maximum number of characters allowed #include <GuiConstants.au3> Opt("GUIOnEventMode", 1) GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("", 80, 50, 270, 170) GUISetOnEvent ($Edit_1, "EditCltEvent" ) GUISetOnEvent ($GUI_EVENT_CLOSE, "close") GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "EditCltEvent" ) GuiSetState() GUISetState(@SW_SHOW) While 1 Sleep(10) Wend Exit Func EditCltEvent() MsgBox(0, "", "Event Received" & @GUI_CTRLID ) EndFunc Func close() if @GUI_CTRLID = $GUI_EVENT_CLOSE Then Exit EndFunc press the right mouse button and you will get the function call EDIT - supposed to be LEFT not right button - sorry Edited July 15, 2006 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Nomad Posted July 15, 2006 Share Posted July 15, 2006 (edited) Would simply typing something into the edit control trigger an event, I want to count the number characters typed into the control as the user types them, and warn the user when they are approaching the maximum number of characters allowed Nope, But you could do a GUICtrlRead() in your waiting loop and do a StringLen(), then make it go to a function if the length is a certain amount. If StringLen(GUICtrlRead($Edit_1)) > 100 Then;or w/e number Function1 () ElseIf StringLen(GUICtrlRead($Edit_1)) > 110 Then Function2 () EndIf Edited July 15, 2006 by Nomad Link to comment Share on other sites More sharing options...
merriman Posted July 15, 2006 Author Share Posted July 15, 2006 Thanks for your replys guys. Best Regards Merriman Link to comment Share on other sites More sharing options...
Nomad Posted July 15, 2006 Share Posted July 15, 2006 Actually, that won't work because it'll keep looping into the function, try something like this:#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("", 80, 50, 270, 170) GUICtrlSetOnEvent ($Edit_1, "EditCltEvent" ) GuiSetState() While 1 Sleep(10) $String = GUICtrlRead($Edit_1) If StringLen($String) = 10 Then EditCltEvent() EndIf Wend Exit Func EditCltEvent() $String = StringTrimRight($String, 1) GUICtrlSetData($Edit_1, $String) MsgBox(0, "", "Event Received") EndFunc Link to comment Share on other sites More sharing options...
Nomad Posted July 15, 2006 Share Posted July 15, 2006 (edited) Sorry, just can't help myself Something like this would probably be more what you're looking for:#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("", 80, 50, 270, 170) GuiSetState() $Var = 10 While 1 Sleep(20) $String = GUICtrlRead($Edit_1) If StringLen($String) >= $Var Then EditCltEvent() EndIf Wend Exit Func EditCltEvent() If $Var < 15 Then MsgBox(0, "Event Received", "WARNING! Approaching character limit") $Var += 1 Sleep(20) ElseIf $Var >= 15 Then $String = StringTrimRight($String, 1) GUICtrlSetData($Edit_1, $String) MsgBox(0, "Event Received", "WARNING! Character limit Exceeded") Sleep(20) EndIf EndFunc Nomad Edited July 15, 2006 by Nomad Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Share Posted July 15, 2006 (edited) How about this: expandcollapse popup#include <GuiConstants.au3> Global $stop = 0, $test Opt("GUIOnEventMode", 1) GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Edit_1 = GuiCtrlCreateEdit("", 80, 50, 270, 170) GUISetOnEvent ($Edit_1, "EditCltEvent" ) GUISetOnEvent ($GUI_EVENT_CLOSE, "close") GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "EditCltEvent" ) GuiSetState() GUISetState(@SW_SHOW) While 1 Sleep(10) If StringLen(GUICtrlRead($Edit_1)) >= 10 and $stop = 0 Then;or w/e number $test = StringLen(GUICtrlRead($Edit_1)) exceed() ElseIf StringLen(GUICtrlRead($Edit_1)) >= 11 and $stop = 1 Then $test = StringLen(GUICtrlRead($Edit_1)) EditCltEvent() EndIf Wend Exit Func exceed() MsgBox(0,"Exceeded Characters", $test) $stop = 1 EndFunc Func EditCltEvent() MsgBox(0, "", "Event Received" & " test = " & $test) $stop = 5 EndFunc Func close() if @GUI_CTRLID = $GUI_EVENT_CLOSE Then Exit EndFunc edit - took out commented test, not needed Edited July 15, 2006 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 GUICtrlSetLimit() Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Nomad Posted July 15, 2006 Share Posted July 15, 2006 GUICtrlSetLimit()Yeah. But he also wanted a notification of when the user was approaching the limit. 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