AutoHotkey Community

It is currently May 26th, 2012, 4:22 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: March 24th, 2009, 9:20 pm 
Offline

Joined: November 24th, 2008, 7:22 pm
Posts: 73
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 12:18 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5479
Location: the tunnel(?=light)
Place this in your script to retrieve the unique ID of the active window just before it would lose focus:

Code:
last:=WinActive(A)


And place this at the end of the script just before it terminates:

Code:
WinActivate, ahk_id %last%


Untested.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 3:39 pm 
Offline

Joined: November 24th, 2008, 7:22 pm
Posts: 73
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 5:10 pm 
The script mentioned here might help you to activate the topmost window.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2009, 8:23 pm 
Offline

Joined: November 24th, 2008, 7:22 pm
Posts: 73
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Cerberus, poserpro, SKAN, tterB, Yahoo [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group