Baritonomarchetto Posted June 22, 2012 Share Posted June 22, 2012 Hi, I want my script to be run only when a CLASS notepad is up on the screen. I wrote a little script like this: #include <Misc.au3> Local $hDLL = DllOpen("user32.dll") WinWaitActive("[CLASS:Notepad]") While 1 If _IsPressed("28", $hDLL) Then; 28 DOWN ARROW ... ... ... EndIf WEnd DllClose($hDLL) this code IS NOT executed only when notepad is up, but always ... what is wrong with it? Thanks Link to comment Share on other sites More sharing options...
JohnOne Posted June 22, 2012 Share Posted June 22, 2012 I'm not 100% certain about this, but I think WinWaitActive employs a default timeout. A quick forum search should clear that up for you. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Baritonomarchetto Posted June 22, 2012 Author Share Posted June 22, 2012 (edited) Thanks for the reply. The timeout is optional and should be disabled if not defined, isn't it? I noticed that the problem is only with notepad: if i try the same with Word, i.e., it works flawless ... maybe Au3Info gave ma an incorrect data because of some language "friction"? Being related to WinWaitActive, may I ask if is possible to define more than one "active" program to use the script with? Or should I compile two identical scripts defining a different WinWaitActive each? Thanks Edited June 22, 2012 by Baritonomarchetto Link to comment Share on other sites More sharing options...
JohnOne Posted June 22, 2012 Share Posted June 22, 2012 (edited) You could just as easily put such code in one script. One such way would be something like this. While 1 If WinActive("1....","") Or WinActive("2....","") Then ExitLoop EndIf Sleep(100) WEnd ;more code Edited June 22, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Baritonomarchetto Posted June 22, 2012 Author Share Posted June 22, 2012 (edited) Thanks John for yout fast replies Let me ask you another thing, related to WinWaitActive: i placed it in a loop in order to avoid the script to act with other programs when the target program is not "active" (I want my script to run always in background and act only on one program, the target, wich becomes active, then inactive, etc and not other programs running at the same time). I noticed that the whole script became "heavy" in this way. Is there another solution other than defining WinWaitActive in a loop like: #include <Misc.au3> Local $hDLL = DllOpen("user32.dll") While 1 If _IsPressed("28", $hDLL) And WinWaitActive("[CLASS:Notepad]") Then; 28 DOWN ARROW ... ... ... EndIf WEnd DllClose($hDLL) Edited June 22, 2012 by Baritonomarchetto Link to comment Share on other sites More sharing options...
JohnOne Posted June 23, 2012 Share Posted June 23, 2012 Yes, use WinActive, not WinWaitActive, and add a Sleep in your loop. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Baritonomarchetto Posted June 23, 2012 Author Share Posted June 23, 2012 Thanks John: it works perfectly now 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