Sign in to follow this  
Followers 0
Baritonomarchetto

WinWaitActive usage for class definition

7 posts in this topic

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

Share this post


Link to post
Share on other sites



#3 ·  Posted (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 by Baritonomarchetto

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Baritonomarchetto

Share this post


Link to post
Share on other sites

Thanks John: it works perfectly now ;)

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