Sign in to follow this  
Followers 0
merriman

Control event problem.

25 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

try GUIOnEventMode in the help file

#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 by nitekram

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

 

WindowsError.gif

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

Share this post


Link to post
Share on other sites

Must not use GUIGetMsg() with GUIOnEventMode keep in mind.


[center]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.[/center]

Share this post


Link to post
Share on other sites

Thanks for your reply guys. Ive tried what you suggested, but it only seems to work on button clicks.


Best Regards Merriman

Share this post


Link to post
Share on other sites

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

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

 

WindowsError.gif

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

Share this post


Link to post
Share on other sites

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 :D


Share this post


Link to post
Share on other sites

Could you be more specific? What do you mean?

Nomad :D

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

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by Nomad

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

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

 

WindowsError.gif

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

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by Nomad

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#13 ·  Posted (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 by nitekram

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

 

WindowsError.gif

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

Share this post


Link to post
Share on other sites

#14 ·  Posted (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 by Nomad

Share this post


Link to post
Share on other sites

Thanks for your replys guys.


Best Regards Merriman

Share this post


Link to post
Share on other sites

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


Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Sorry, just can't help myself :wacko:

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 :D

Edited by Nomad

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

How about this:

#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 by nitekram

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

 

WindowsError.gif

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

Share this post


Link to post
Share on other sites

GUICtrlSetLimit()


[center]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.[/center]

Share this post


Link to post
Share on other sites

GUICtrlSetLimit()

Yeah. :D

But he also wanted a notification of when the user was approaching the limit.


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  
Followers 0