| View previous topic :: View next topic |
| Author |
Message |
Relayer
Joined: 24 Nov 2008 Posts: 68
|
Posted: Tue Mar 24, 2009 8:20 pm Post subject: Starting scripts with a windows shortcut? |
|
|
Hi,
I have several scripts that I want to launch by clicking a shortcut contained in a toolbar. The shortcut launches the script which does its thing and then terminates itself. The scripts do specific things that often involve sending text. Here's my issue: how do I reliably return focus to the window that previously held it before I clicked on the shortcut? The act of clicking the shortcut takes focus from my "target" window.
This target window will not have a consistent name or other ID. I have used {Alt Down}{TAB}{Alt Up} with reasonable success but it does not work, for instance, when a new notepad is opened and I click a shortcut before doing any action inside notepad window. Notepad has the focus just before launching the script but it is not located in the windows AltTab list in the right spot for my AltTab to work. It gives focus to an unintended window.
So, the script has no apriori knowledge of the target window it will be playing in and the focus of the target is lost as a result of launching the script with the windows shortcut.
Thanks in advance,
Relayer |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Tue Mar 24, 2009 11:18 pm Post subject: |
|
|
Place this in your script to retrieve the unique ID of the active window just before it would lose focus:
And place this at the end of the script just before it terminates:
| Code: | | WinActivate, ahk_id %last% |
Untested. _________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
Relayer
Joined: 24 Nov 2008 Posts: 68
|
Posted: Wed Mar 25, 2009 2:39 pm Post subject: |
|
|
That would work if my script were running at the time my target window loses focus. That's the rub. Clicking the shortcut starts my script and simultaneously steals the focus.
Perhaps it's not possible to do it this way. Maybe I need to have a script running in the background but that adds a lot of complexity to executing fairly simple standalone utilities.
Relayer |
|
| Back to top |
|
 |
sinkfaze n-l-i Guest
|
|
| Back to top |
|
 |
Relayer
Joined: 24 Nov 2008 Posts: 68
|
Posted: Wed Mar 25, 2009 7:23 pm Post subject: |
|
|
sinkfaze,
Nice. I have it in testing now. I think this might also solve another problem that has been breakin' my b@%%$. I'll say more when testing is done! Thanks.
Relayer |
|
| Back to top |
|
 |
|