Jump to content
Macro Express Forums

"Activate window" unstable ?


Recommended Posts

Hello,

 

Everytime I use this feature, there is an unstability when the software use a little the cpu/gpu. It works only 4/5 times, but it's not good, it must be 5/5.

 

The problem : sometime, ME pro don't activate a window, even with the loops I done with "repeat"...

 

90854420161029130917.jpg26709320161029130927.jpg

<COMMENT _BACK="000080FF"/>
<REPEAT START Start="1" Step="1" Count="%nb_de_comptes%" Save="FALSE" _FORE="00000000" _BACK="000080FF"/>
<COMMENT/>
<COMMENT Value="Clic." _FORE="00FFFFFF" _BACK="00004000"/>
<MOUSE MOVE Option="\x01" X="%N[1]%" Y="%N[2]%" _PROMPT="0x000A" _FORE="00FFFFFF" _BACK="00808040"/>
<MOUSE LEFT CLICK _FORE="00FFFFFF" _BACK="00808040"/>
<COMMENT/>
<COMMENT Value="Si demande pour rejoindre combat." _FORE="00FFFFFF" _BACK="00004000"/>
<GET PIXEL COLOR Option="\x01" Rel_To_Screen="TRUE" X="%pos_interrogation_invitation[1]%" Y="%pos_interrogation_invitation[2]%" Destination="%N[3]%" _FORE="00FFFFFF" _BACK="00808040"/>
<IF VARIABLE Variable="%N[3]%" Condition="\x00" Value="%bleu_invitation%" IgnoreCase="FALSE" _FORE="00FFFFFF" _BACK="00808040"/>
<DELAY Flags="\x02" Time="%delay_joint_combat%" _FORE="00FFFFFF" _BACK="00808040"/>
<END IF _FORE="00FFFFFF" _BACK="00808040"/>
<COMMENT/>
<COMMENT Value="Reset :" _FORE="00FFFFFF" _BACK="00004000"/>
<VARIABLE SET STRING Option="\x00" Destination="%active_window%" NoEmbeddedVars="FALSE" _FORE="00FFFFFF" _BACK="00808040"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[3]%" Value="0" _FORE="00FFFFFF" _BACK="00808040"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[4]%" Value="1" _FORE="00FFFFFF" _BACK="00808040"/>
<COMMENT/>
<REPEAT START Start="1" Step="1" Count="%nb_de_comptes%" Save="FALSE" _FORE="00000000" _BACK="000080FF"/>
<VARIABLE MODIFY INTEGER Option="\x00" Destination="%N[3]%" Value1="%N[3]%" Value2="1" _FORE="00FFFFFF" _BACK="00808040"/>
<VARIABLE MODIFY INTEGER Option="\x00" Destination="%N[4]%" Value1="%N[4]%" Value2="1" _FORE="00FFFFFF" _BACK="00808040"/>
<COMMENT _FORE="00FFFFFF" _BACK="00808040"/>
<IF WINDOW Option="\x00" Title="%persos[%nb_de_comptes%]%" Partial="FALSE" Wildcards="FALSE" _FORE="00FFFFFF" _BACK="00808040"/>
<REPEAT UNTIL Variable="%active_window%" Condition="\x00" Value="%persos[1]%" _FORE="00FFFFFF" _BACK="00808040"/>
<DELAY Flags="\x12" Time="20" _COMMENT="CPU." _FORE="00FFFFFF" _BACK="00808040"/>
<WINDOW ACTIVATE Title="%persos[1]%" Exact_Match="TRUE" Wildcards="FALSE" _IGNORE="0x0006" _FORE="00FFFFFF" _BACK="00808040"/>
<WAIT FOR WINDOW TITLE Title="%persos[1]%" Partial="FALSE" Wildcards="FALSE" Indefinite="TRUE" Hours="0" Minutes="0" Seconds="0" _FORE="00FFFFFF" _BACK="00808040"/>
<VARIABLE SET STRING Option="\x05" Destination="%active_window%" _FORE="00FFFFFF" _BACK="00808040"/>
<GOTO Name="Ok." _FORE="00FFFFFF" _BACK="000000FF"/>
<END REPEAT _FORE="00FFFFFF" _BACK="00808040"/>
<ELSE _FORE="00FFFFFF" _BACK="00808040"/>
<IF WINDOW Option="\x00" Title="%persos[%N[3]%]%" Partial="FALSE" Wildcards="FALSE" _FORE="00FFFFFF" _BACK="00808040"/>
<REPEAT UNTIL Variable="%active_window%" Condition="\x00" Value="%persos[%N[4]%]%" _FORE="00FFFFFF" _BACK="00808040"/>
<DELAY Flags="\x12" Time="20" _COMMENT="CPU." _FORE="00FFFFFF" _BACK="00808040"/>
<WINDOW ACTIVATE Title="%persos[%N[4]%]%" Exact_Match="TRUE" Wildcards="FALSE" _IGNORE="0x0006" _FORE="00FFFFFF" _BACK="00808040"/>
<VARIABLE SET STRING Option="\x05" Destination="%active_window%" _FORE="00FFFFFF" _BACK="00808040"/>
<GOTO Name="Ok." _FORE="00FFFFFF" _BACK="000000FF"/>
<END REPEAT _FORE="00FFFFFF" _BACK="00808040"/>
<END IF _FORE="00FFFFFF" _BACK="00808040"/>
<END IF _FORE="00FFFFFF" _BACK="00808040"/>
<COMMENT _FORE="00FFFFFF" _BACK="00808040"/>
<END REPEAT _FORE="00000000" _BACK="000080FF"/>
<COMMENT _BACK="00808040"/>
<LABEL Name="Ok." _FORE="00FFFFFF" _BACK="000000FF"/>
<DELAY Flags="\x12" Time="180" _COMMENT="délai supplémentaire de sécurité." _FORE="00FFFFFF" _BACK="00808040"/>
<IF VARIABLE Variable="%delay_chg_perso%" Condition="\x00" Value="1" IgnoreCase="FALSE" _ENABLED="FALSE" _COMMENT="Si l'option est activée." _FORE="00FFFFFF" _BACK="00808040"/>
<DELAY Flags="\x02" Time="%random_delai%" _ENABLED="FALSE" _FORE="00FFFFFF" _BACK="00808040"/>
<END IF _ENABLED="FALSE" _FORE="00FFFFFF" _BACK="00808040"/>
<COMMENT _BACK="00808040"/>
<END REPEAT _FORE="00000000" _BACK="000080FF"/>
<COMMENT _BACK="000080FF"/>

I don't know why, but I always have this problem with softwares that lag a little...

Link to comment
Share on other sites

Are you sure the window you want to activate is running? If you kill the macro and Alt-Tab by hand, can you find it running?

 

Other than that, I'd try making the delays about 100ms instead of 20ms, and place the delay immediately AFTER the activate line instead of before it. In other words, give Windows a little time after the command to activate, before setting the variable to topmost window name.

 

Also I don't understand the Goto: OK commands. It looks like they take you out of the internal Repeat loops, back to the outer loop where the Reset commands clear out the stored name of the active window.

Link to comment
Share on other sites

So you're hunting for a Window? Beware that scanning pixel colors can get really slow in Windows 10. I think it was Terry that was having problems with that recently. I don't know why you're doing it this way but it seems wrong. Why are you resorting to such an extreme and problematic method?

 

BTW GoTo is considered a bad practice in programming by most. It should be avoided. Once in a blue moon I'll use one but the overwhelming majority of the time there's a better way to structure your logic. IE the existence of a GoTo often indicates a misunderstanding in how to structure logic.

Link to comment
Share on other sites

Hello,

 

-Sure, the window is running.

-The "goto:ok" are functionals, and that bug happent before I used it.

-I don't use W10, but W7.

-I not a pixel color detection problem, only an "active window" problem, the macro just stop trying to load it, and stop the loop I done for security, but the macro don't stop.

 

I actualy test your delays rberq.

Link to comment
Share on other sites

I often find that Wait for Window Title fails. My first step is to simply replace it with a short delay, typically 0.1 to 0.3 s.

 

But Activate Window also fails sometimes. I then try various alternatives, including pixel colour tests (usually 2 or 3 AND sets to minimise ambiguity).

 

And I've found that a macro's reliability/stability can depend on other factors outside MX Pro, probably reflecting timing issues. Maybe also the current phase of the Moon. As Cory mentioned, Win 10 has the added problem of much slower pixel recognition.

 

Interesting colouring of your messages. How are you doing it?

 

 

Terry, East Grinstead, UK

Link to comment
Share on other sites

Yes I don't use "wait for window" too, I forgotten to remove it here, but I done this repeat only to replace it :

Repeat Until %active_window% Equals "%persos[1]%"
Window Activate: %persos[1]%
Variable Set String %active_window% to topmost window title
End Repeat
Or with a pixel detection too, for some uses. And I done a calibrating system, that opens when the macro don't find the pixel several times, that ask the new position/pixel to verify (in just one clic), and change the variables values (saved on file) to reopen it. Usefull when the software changes, or when you change the interface = the pixel changes too.
I don't use W10.
No one updates ME pro to fix this unstability ?
For coloring : right clic on code.
Link to comment
Share on other sites

I'm not exactly sure what your macro logic is doing but it looks like the topmost repeat does not exit when you find one of the two active windows. Could it be that the Activate Window command is working but your macro does not stop?

 

I would write this a little differently. Here is your macro with some commands rearranged and the GoTo commands removed. (Lines with <-- are new):

Variable Set String %StopNow% to "FALSE" // <--
Repeat Start (Repeat %nb_de_comptes% times)
 
// Clic.
  Mouse Move: %N[1]%, %N[2]% Relative to Screen
  Mouse Left Click
   
  // Si demande pour rejoindre combat.
  Get Pixel Color at (%pos_interrogation_invitation[1]%, %pos_interrogation_invitation[2]%) Relative to Screen into %N[3]%
  If Variable %N[3]% Equals "%bleu_invitation%"
    Delay: %delay_joint_combat% milliseconds
  End If
   
  // Reset :
  Variable Set String %active_window% to ""
  Variable Set Integer %N[3]% to 0
  Variable Set Integer %N[4]% to 1
   
   
  Variable Set String %active_window% to "" // Initialize this variable in case the If commands below fail <--
  Repeat Start (Repeat %nb_de_comptes% times)
    Variable Modify Integer: %N[3]% = %N[3]% + 1
    Variable Modify Integer: %N[4]% = %N[4]% + 1
     
    If Window "%persos[%nb_de_comptes%]%" is focused
      Repeat Until %active_window% Equals "%persos[1]%"
        Window Activate: %persos[1]%
        Wait for Window Title: %persos[1]%
        Delay: 20 milliseconds // CPU.
        Variable Set String %active_window% to topmost window title
        Variable Set String %StopNow% to "TRUE" // <--
        Repeat Exit // <--
      End Repeat
    Else
      If Window "%persos[%N[3]%]%" is focused
        Repeat Until %active_window% Equals "%persos[%N[4]%]%"
          Window Activate: %persos[%N[4]%]%
          Delay: 20 milliseconds // CPU.
          Variable Set String %active_window% to topmost window title
          Variable Set String %StopNow% to "TRUE" // <--
          Repeat Exit // <--
        End Repeat
      End If
    End If
    Delay: 20 milliseconds // CPU.
     
    If Variable %StopNow% Equals "TRUE" // <--
      Repeat Exit // <--
    End If // <--
  End Repeat
   
  :Ok.
  Delay: 180 milliseconds // délai supplémentaire de sécurité.
  If Variable %delay_chg_perso% Equals "1" // Si l'option est activée.
  Delay: %random_delai% milliseconds
  End If
   
  If Variable %StopNow% Equals "TRUE" // <--
    Repeat Exit // <--
  End If // <--
End Repeat

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...