TsunamiZ Posted January 1, 2011 Report Share Posted January 1, 2011 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. Quote Link to comment Share on other sites More sharing options...
kevin Posted January 1, 2011 Report Share Posted January 1, 2011 Try putting this at the beginning of your macro: Variable Set String %LastFocusedWin% to topmost window title And this at the end: Window Activate: %LastFocusedWin% Quote Link to comment Share on other sites More sharing options...
TsunamiZ Posted January 1, 2011 Author Report Share Posted January 1, 2011 i forgot to mention, i have to activate the macro on the taskbar. and i want it to activate the last focussed window after the macro runs. is it still possible to activate the last focussed window after a macro runs, if the macro is activated outside the window? Quote Link to comment Share on other sites More sharing options...
acantor Posted January 3, 2011 Report Share Posted January 3, 2011 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. Quote Link to comment Share on other sites More sharing options...
TsunamiZ Posted January 3, 2011 Author Report Share Posted January 3, 2011 is there a command to activate the topmost or second topmost window? Quote Link to comment Share on other sites More sharing options...
acantor Posted January 3, 2011 Report Share Posted January 3, 2011 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? Quote Link to comment Share on other sites More sharing options...
TsunamiZ Posted January 3, 2011 Author Report Share Posted January 3, 2011 i can only use mouse activation for my scenario, because it is more convenient Quote Link to comment Share on other sites More sharing options...
acantor Posted January 3, 2011 Report Share Posted January 3, 2011 Would it work if you clicked part of the window instead of the task bar? It's fairly straightforward to activate a macro by, for example, right clicking a maximize button, a title bar, or a menu. Then your script could collect information about the focused window. Quote Link to comment Share on other sites More sharing options...
TsunamiZ Posted January 3, 2011 Author Report Share Posted January 3, 2011 my macro has to click the taskbar because my macro can't be activated in a window. since it uses a global hotkey for a program, it can potentially cause hotkey conflicts if activated in a window. so i'm looking for a way to activate previous window. Quote Link to comment Share on other sites More sharing options...
acantor Posted January 3, 2011 Report Share Posted January 3, 2011 I don't think that there is a reliable way to do this, but you might want to investigate the possibility of using the new Z-order options that are part of the "Get Control" commands in Macro Express Pro. Quote Link to comment Share on other sites More sharing options...
TsunamiZ Posted September 12, 2011 Author Report Share Posted September 12, 2011 i finally found a way to do this on windows 7 using the flip 3d [WIN+TAB]. unlike ALT+TAB, the order of flip 3d is reliable. so i add this to the end of the macro... <WIND><TAB> delay 10 ms <WINU> i hope it helps someone else too Quote Link to comment Share on other sites More sharing options...
MakaPakaTobyHannah Posted October 4, 2011 Report Share Posted October 4, 2011 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! Quote Link to comment Share on other sites More sharing options...
TsunamiZ Posted October 4, 2011 Author Report Share Posted October 4, 2011 btw, i used this for a macro that is activated with a middle click on the taskbar Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.