Jump to content
Macro Express Forums

Method to switch back to previously focussed window after running macro?


Recommended Posts

Anyone know if there is a macro method to switch back to previously focussed window after running a macro? It has to be a previously focussed window and not a specific window. I've already tried various (SHIFT+)ALT+TAB tricks but they don't work reliably because results differ between having 1 or 2+ windows. I'm on Windows 7.

Link to comment
Share on other sites

I don't think MEP can detect which window was focused before you activate the macro. If the macro must be activated from the System Tray or Desktop, problems are inevitable. You might try switching focus using Alt + Esc or Shift + Alt + Esc, but my guess is that you will run into the same problem as you did when using Alt + Tab.

 

Your best best may be to change the activation to Hotkey or ShortKey.

Link to comment
Share on other sites

I don't think so. At least not a built-in command. What happens when two (or more) windows are tiled without overlapping? In that case, there could be two (or more) topmost windows.

 

Macro Express cannot read the mind of the user. It cannot know what the user was doing, and in which window, prior to activating a macro. It can only act upon information available the moment the macro is activated -- unless information about window usage is being logged.

 

It might be possible to create macros that track each window that is activated, and that log this information in a file. My guess is that you would need 26 macros: one activated by window title that contains an "a," another by a "b," etc. When a window gains focus, the name of the window is recorded and saved to a file.

 

(I can imagine all sorts of problems in trying to do this!)

 

When the macro in the System Tray is activated, it parses the file to determine the last window title to have focus.

 

Is it possible to do this? Maybe. But it may be too complex to be practical.

 

Are you sure you can't use hotkey activation?

Link to comment
Share on other sites

  • 8 months later...
  • 4 weeks later...

This is an older post by now, so probably no longer acute. Still, I think there is an easier solution - if I understand fully what is desired.

 

It sounds as if the main problem is that you don't want to use a hotkey to activate the macro, but want to constrain yourself to activating the macro from a menu. The trouble is, when you do so, the "topmost window" once you activate your macro is the macro activation list itself, not the window that was active just before you go into the macro activation list. I solve this problem like this:

 

>>

// Comment: The following delay has been inserted in case the macro is invoked from a menu. In that case, the "topmost window," when the macro starts executing, might in fact be the menu window itself, causing the macro to fault.

Delay: .2 seconds

<<

 

That works without fail: once you activate the macro from the list, the "macro activation list" window disappears, and the focus returns to the window that was active before you activated the macro. Then you can capture the window title etc. etc. in the usual way.

 

Maybe the issue isn't quite this... in which case I'll try posting a different solution.

 

Cheers!

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