AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Starting scripts with a windows shortcut?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Relayer



Joined: 24 Nov 2008
Posts: 68

PostPosted: Tue Mar 24, 2009 8:20 pm    Post subject: Starting scripts with a windows shortcut? Reply with quote

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
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Tue Mar 24, 2009 11:18 pm    Post subject: Reply with quote

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.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Relayer



Joined: 24 Nov 2008
Posts: 68

PostPosted: Wed Mar 25, 2009 2:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
sinkfaze n-l-i
Guest





PostPosted: Wed Mar 25, 2009 4:10 pm    Post subject: Reply with quote

The script mentioned here might help you to activate the topmost window.
Back to top
Relayer



Joined: 24 Nov 2008
Posts: 68

PostPosted: Wed Mar 25, 2009 7:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group