AutoHotkey Community

It is currently May 27th, 2012, 7:39 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: September 13th, 2006, 2:49 pm 
Offline

Joined: January 1st, 2006, 6:26 pm
Posts: 55
I have multiple gui's running on the system in a hidden state. When I press a hotkey, I want one of them unhidden depending on which window is active at the time; e.g. if Xplorer is active, one gui is unhidden, if opera is active, another gui is unhidden. Ideally I'd prefer to keep these guis each in a separate file, for ease of maintenance. This would mean each of these guis would need to have a rbutton shortcut defined that checks which window is active and either unhides itself or does nothing.

Unfortunately, if many scripts define the same shortcut only the shortcut in the last-defined is active.

Another alternative is to have a separate chooser script that defines a shortcut that checks which window is currently active and unhides a gui based on that, but it needs to be able to send a command 'gui show ...' to a separate running script.

Another alternative is to have them all in the same script, and with each gui going by a number, 1, 2, 3, ... . This will make it a bit hard to maintain because each of the scripts can be about 100-300 lines and eventually there may be 10-15 of them, and some of them would be the same on all systems I use, while others may be somewhat different on each system, depending for example on OS, directories set up, version of an application the script works with, etc.

Which is the easiest and preferred option of these three? Thanks!

_________________
-AK


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 3:13 pm 
Offline

Joined: June 10th, 2006, 11:26 am
Posts: 67
Location: Bratislava, Slovakia
I'd use one script which would contain the shortcut to activate the correct gui and #Include the gui scripts in this "main" script.

Roman


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 3:14 pm 
Offline

Joined: January 1st, 2006, 6:26 pm
Posts: 55
Great! I didn't even think about #include... Glad I asked, I was almost decided just to move them alltogether...... that would suck.

_________________
-AK


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 3:21 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Please take a look at this:
http://www.autohotkey.com/forum/viewtop ... 0710#30710

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 4:33 pm 
Offline

Joined: January 1st, 2006, 6:26 pm
Posts: 55
Toralf, thanks, but I have a question: I need to gosub to functions defined in the included files, therefore it seems to me that your method won't work because I can't go to functions inside the functions.

_________________
-AK


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 4:40 pm 
Offline

Joined: January 1st, 2006, 6:26 pm
Posts: 55
I have a further question... I tried the method of using includes and when I put them into my original scripts, on a shortcut they do come up but they're missing all the buttons and gui options that are set up in autoexecute portion. It's as if autoexecute is completely forgotten by the time a gosub is run.. I tried to reduce this to 3 small files which I'm posting, by the way these three files don't even show the gui at all.. I'm at a loss here, please help anybody! I feel like there's some stupid mistake like a missing comma or something here..

try.ahk:
Code:

#include tryx.ahk
return
#include tryy.ahk
return

gosub tryx
sleep 3000
gosub tryy

GuiClose:
gui 2: show
return

2guiclose:
ExitApp


tryx.ahk:

Code:
Gui  Add, Button, x46 y20 w30 h20 gaction, Up
Gui  Add, Button, x6 y20 w30 h20 gaction, Del
return

action:
 return

tryx:
 gui show, x0 y0 h100 w200
return


tryy.ahk:

Code:
Gui 2:  Add, Button, x46 y20 w30 h20 gaction2, Up
Gui 2: Add, Button, x6 y20 w30 h20 gaction2, Del
return

action2:
 return

tryy:
 gui 2: show
return

_________________
-AK


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 7:31 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
The solution is in the "return"s.
Think of #Include as if the file is copied to that place. Now do this for the three files. What you get is
Code:
Gui  Add, Button, x46 y20 w30 h20 gaction, Up
Gui  Add, Button, x6 y20 w30 h20 gaction, Del
return

action:
 return

tryx:
 gui show, x0 y0 h100 w200
return

return
Gui 2:  Add, Button, x46 y20 w30 h20 gaction2, Up
Gui 2: Add, Button, x6 y20 w30 h20 gaction2, Del
return

action2:
 return

tryy:
 gui 2: show
return
return

gosub tryx
sleep 3000
gosub tryy

GuiClose:
gui 2: show
return

2guiclose:
ExitApp
Now tell me, why this isn't working. :)

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 9:35 pm 
Offline

Joined: January 1st, 2006, 6:26 pm
Posts: 55
I knew about #include but I thought return works like it does in Python, where you can have some statements, then a function def ending with a return, then some more statements, etc etc, and return merely terminates the function, the following statements will still run. So if I understood right, in AHK anything after a function def won't run? thanks for helping me out I'd never guess :)

_________________
-AK


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 9:49 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
A Return is the end of a sub-routine, hotkey, hotstring or of a function or of the auto-exec section. After that AHK will stop after the return and wait for the next action (e.g. hotkey) or return to the position where the routine was called with GoSub and continue with the next command after GoSub.
Thus you have to be careful where you put the Returns, so that all auto-exec sections are executed with multiple includes. That what I wrote in the post I gave you the link.

_________________
Ciao
toralf
Image


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: HotkeyStick, sjc1000, SKAN, tomL and 71 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