pdaughe Posted December 22, 2006 Share Posted December 22, 2006 The following is the sample script for GUISetOnEvent in the AutoIT help documentation. Note the two statements I added (<------ added to sample script): CODE#include <GUIConstants.au3> Opt("GUICoordMode",2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) $parent1 = GUICreate("Parent1") GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "SpecialEvents") ; <--------- added to sample script $ok1 = GUICtrlCreateButton ("OK", 10, 30, 50) GUICtrlSetOnEvent(-1, "OKPressed") $cancel1 = GUICtrlCreateButton ( "Cancel", 0, -1) GUICtrlSetOnEvent(-1, "CancelPressed") GUISetState(@SW_SHOW) ; Just idle around While 1 Sleep(10) Wend 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) Case @GUI_CTRLID = $GUI_EVENT_PRIMARYDOWN ; <------------------------------------------ added to sample script MsgBox(0, "Mouse Left Down", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) EndSelect EndFunc Run the script and observe the behavior. What happens when you press the primary mouse button down on just the GUI window? -- repeatedly. Then, press the left mouse button down on the "OK" button, then do it again, repeatedly. Then alternate pressing the left mouse button down on the OK button then the Cancel button. I am running beta 3.2.0.1. It seems to me the behavior is unpredictable. I'm I right or wrong? I would appreciate it if someone could help me understand what's going on. Thanks for your help. Link to comment Share on other sites More sharing options...
jpm Posted December 22, 2006 Share Posted December 22, 2006 If you use the beta 3.2.1.14 or the rc3 you will get a deterministic behavior the $GUI_EVENT_PRIMARYDOWN will always fire as it is the first event detected. Link to comment Share on other sites More sharing options...
pdaughe Posted December 22, 2006 Author Share Posted December 22, 2006 If you use the beta 3.2.1.14 or the rc3 you will get a deterministic behavior the $GUI_EVENT_PRIMARYDOWN will always fire as it is the first event detected.Thanks so much -- upgrading now. Link to comment Share on other sites More sharing options...
pdaughe Posted December 22, 2006 Author Share Posted December 22, 2006 Thanks so much -- upgrading now.I upgraded to 3.2.1.14 beta and tested. Then I upgraded to 3.2.2.0 -RC3 and tested. In both of these releases, the behavior is "deterministic as JPM indicated. HOWEVER, now I never see the $GUI_EVENT_PRIMARYUP event. In the sample I posted previously, pressing the left mouse button on either control, or the window itself, fires the PRIMARYDOWN event, but not the PRIMARYUP event when the left mouse button is released. My expectation, based on my understanding (which admittedly may be incorrect) is that the PRIMARYDOWN event would be fired when the left mouse button is pressed and the PRIMARYUP event would be fired when the button is released.Do you observe the same behaviour?Thanks again for you help --- seriously, 1 hour and 40 minutes later after my initial post -- wow, I only ever have called MS support once in my life; would anybody ever call again (a little humor here).As an aside, after upgrading when I do a syntax check under SciTE, I get the message:! *** AU3CHECK Error: *** Skipping AU3Check: \au3check.exe Not Found !I verified that AU3CHECK is in the AutoIT directory and the Beta directory, I just can't figure out how to tell SciTE to look there. Link to comment Share on other sites More sharing options...
pdaughe Posted December 22, 2006 Author Share Posted December 22, 2006 (edited) Hmmm, after thinking about it, it seems now I have a logic error. I fire a function on the PRIMARYDOWN event, which goes into a loop until a variable is set by the PRIMARYUP event function. The PRIMARYUP event isn't going to fire until I return to the system, right? Is that correct? If so, then I have to return to the system and THEN check if the left mouse button is still down -- I'm going to test that. If someone reads this in the next couple of hours, please let me know if I'm on the right track. Sincerely, Paul Edit: 11 minutes later. Well, it seems my above understanding was correct. I changed the loop condition to _IsPressed ("01") and it works beautifully! Thanks again for your help JP. I still haven't been about to figure out why SciTE can't find AU3CHECK.exe when doing a beta syntax check though.... Edited December 22, 2006 by pdaughe Link to comment Share on other sites More sharing options...
Valik Posted December 22, 2006 Share Posted December 22, 2006 A second event can not be fired while still within the callback function for the first event. So if your OnPrimaryDown callback is running a loop, you're right, your OnPrimaryUp callback will not be invoked. You can avoid this by setting a flag in OnPrimaryDown and un-setting that flag in OnPrimaryUp. Then in your While loop that keeps the script active, check the condition of the flag. If the flag is down, execute what you need to do while the mouse button is down and poll the flag until it's unset denoting the OnPrimaryUp event fired. pixelsearch 1 Link to comment Share on other sites More sharing options...
pdaughe Posted December 22, 2006 Author Share Posted December 22, 2006 A second event can not be fired while still within the callback function for the first event. So if your OnPrimaryDown callback is running a loop, you're right, your OnPrimaryUp callback will not be invoked. You can avoid this by setting a flag in OnPrimaryDown and un-setting that flag in OnPrimaryUp. Then in your While loop that keeps the script active, check the condition of the flag. If the flag is down, execute what you need to do while the mouse button is down and poll the flag until it's unset denoting the OnPrimaryUp event fired.Thank you very much Valik for your reply. It makes perfect sense NOW. I used the _IsPressed function in the OnPrimaryDown callback and that works great -- there may be some consequences of doing it this way that I don't see -- I do perfectly understand what you wrote (ah, that means I'm coming along! -- programmed IBM mainframes (in assembler language) for thirty years, and although I'll never have the project I'm working on done for my family by Christmas, it's still going to be an appreciated gift!) 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