Jump to content
Macro Express Forums

Lock Player command: when is it safe to remove?


Recommended Posts

Hi All,

I didn't try to do the "Import old macros" option, I just located my ME3 file on my computer and opened it in MEpro. IT seems to have worked fine, but I have noted that as a safety precaution MEpro has inserted "Lock player" and "Unlock" commands at the beginning and ending of each macro. I read in one of the other posts that there is a potential for a conflict if 2 macros are simultaneously sending info to the key-que. I guess there is probably an unlimited number of possible scenarios for conflict, since ME can manipulate *so many* of the Windows OS functions. I'm not an expert, but I suppose any time you try to do two different things to the same file, application, or process at the same time, one of two things will happen: 1. One of the macros won't work; or 2. There will be a crash somewhere.

 

I'm hoping some of our local experts can expand on this... What are the mostly likely scenarios for conflict? When are the Lock/Unlock commands definitely NOT needed in a macro? What are some examples of cases where folks have used the lock?

 

Thanks. :lol:

-steve

Link to comment
Share on other sites

Windows only allows keystrokes, mouse movements and mouse clicks within one window, the one with focus. Any macro that opens a program, activates a window or changes the window that has focus could cause problems if runs while another macro is running. The Unlock Player and Lock Player commands avoid those problems.

 

If your macro is checking, copying or deleting files you are probably safe, unless another macro is depending on one of the affected files.

 

The general rule should be to think when writing your macros "What would happen if another macro started running right here?" If there is a potential for problems you should add Lock Player and Unlock Player commands.

 

When Macros are converted from Macro Express 3, the Lock Player and the Unlock Player commands are added to the top and bottom of the macro, respectively. But it is not required that they be at the top and bottom. You can add them anywhere in your macro. For example:

 

// Do macro commands like copy files, initializing variables and getting things ready for the macro to run.

Lock Player: Wait for running macros to stop // About to enter a critical section
If Not Window "Notepad" is focused
 Activate or Launch: Window "Notepad", Program "notepad.exe", Parameters ""
End If

Text Type (Simulate Keystrokes): This text will be typed into Notepad ...
Unlock Player  // Done with the critical section
//
// Do more macro commands that do not depend on a specific window having focus.
// 
Lock Player: Wait for running macros to stop  // About to enter a critical section
If Not Window "Notepad" is focused
 Activate or Launch: Window "Notepad", Program "notepad.exe", Parameters ""
End If

Mouse Move: 123, 456 Relative to Current Window
Mouse Left Click: 123, 456 Relative to Current Window
Text Type (Simulate Keystrokes): This text will be typed into Notepad ...

Unlock Player  // Done with the critical section

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...