Macroscheduler timing issues

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Krep
Junior Coder
Posts: 31
Joined: Thu Nov 12, 2009 3:56 pm

Macroscheduler timing issues

Post by Krep » Sun Mar 18, 2018 10:06 pm

Hello folks!

I'm running a macroscheduler script which is using the OnEvent>KEY_DOWN,VKx,0,EventSRT1 to kick off a subroutine.

The script has to take a specific action (mouse left click) repeatedly, in a specific timeframe, anywhere from 0.05 seconds to 0.1 seconds (per click), with the specific timing depending on various other program parameters, as long as VKx is held down. While this short time is ticking down, the macro has other things to do, such as a screencompare. This was working great initially using the MacroScheduler built-in Wait> with a hardcoded wait time, but then I noticed under certain periods of higher CPU usage, the program would fall behind and the Wait duration would vary dramatically from the number specified. Setting MacroScheduler to "Above Normal" priority in Windows (10) seemed to help this problem initially, but then I still ran into occasional high-CPU problems. Next, I made my own custom WaitUntil subroutine using VBEval>Timer and after all the other code was done, looping until the correct time had elapsed. This made the problem even more rare, but still under VERY high CPU load occasionally various instructions would take variable execution time, longer than expected, too long before the my custom wait was even reached.

I have a few options, like skipping certain optional code sections when time is running out, combined with using a counting clicks and only running certain code every even/3rd/5th click, etc, but each has drawbacks, and I'd like to understand why this is happening.

Do I need to disable the OnEvent>KEY_DOWN while I'm in the SRT that's being called by it? In other words, can an Event-Handling subroutine (say, EventSRT1) call itself and start over again before it's finished if the event (such as a keypress) happens multiple times, or is held down? And if not, if EventSRT1 calls a sub-subroutine will it also let that sub-subroutine complete, and return to EventSRT1, and finish EventSRT1 before it checks for the Event to reoccur?

Currently, I'm disabling the OnEvent inside EventSRT1, at the beginning, just to make sure it doesn't interrupt itself, then re-enabling it before I leave EventSRT1, but I'm wondering if those code steps are unnecessary and wasting cycles.

Also, I have an OnEvent,KEY_DOWN,VKx,0,EventSRT1 and a OnEvent,KEY_DOWN,VKx,1,EventSRT1, to protect for the case where the key is pressed with Shift also held down... Is the Extra parameter 0/1 optional, could I just do OnEvent,KEY_DOWN,VKx,,EventSRT1 or is there a way to run it regardless of if the shift or any other modifier key is pressed? Or I need to keep the two statements?

Also, currently I have a separate OnEvent,KEY_DOWN for a "Pause" key to halt the macro, because it doesn't seem to respond to Alt+ESC. Can I speed up code execution by removing that key and/or is there a way to make Alt+ESC work better? Or maybe I just need to hit it several times for it to work (which would be acceptable if it speeds up execution significantly -- but I gave up on it a while back).

Any other tips for speeding up MacroScheduler code execution? Should I try setting the priority to High or Realtime, instead of just "Above Normal"? Should I change some of the other competing processes and set their afinity to leave some of my CPU cores alone in hopes that Windows will allocate those cores to MacroScheduler? Other suggestions? My PC is a i7 8700K, fairly top of the line in terms of speed...

Unfortunately for me the problem is hard to reproduce and debug, since it has to happen under heavily loaded conditions and very tight timing, so I was looking for other folks who may have experience with this problem...

Thanks for any help folks can provide!!

-Krep

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Macroscheduler timing issues

Post by Marcus Tettmar » Mon Mar 19, 2018 1:03 pm

OnEvent won't fire while inside it's subroutine.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts