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 

Newbie questions

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






PostPosted: Tue Jun 29, 2004 12:45 pm    Post subject: Newbie questions Reply with quote

Hello,

few things that I can't figure out this alone ...

- is it possible to load/unload one script from
another?

- can I have different groups or sets of hotkeys
associated with different applications, for
example, if I open IE, Word and Excel, can each
of them have it's on script which doesn't
interfere with other ones?

Thanks for any help.
Back to top
beardboy



Joined: 02 Mar 2004
Posts: 444
Location: SLC, Utah

PostPosted: Wed Jun 30, 2004 1:06 am    Post subject: Reply with quote

Quote:
- is it possible to load/unload one script from
another?

Yes, I have two compiled scripts that I use together. One is #Include'd in the other, and both have the ability to interact with the other by them storing variables in an INI file and checking the values on a regular basis.
Quote:
- can I have different groups or sets of hotkeys
associated with different applications, for
example, if I open IE, Word and Excel, can each
of them have it's on script which doesn't
interfere with other ones?

You can setup multiple scripts or one big script and have multiple hotkeys. You can even setup hotkeys to do different things based on which windows exist or is currently active. It all just depends on what you want to do.

Let me know if you needs some code examples for either of the above.

thanks,
beardboy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed Jun 30, 2004 2:08 am    Post subject: Reply with quote

There's a section in the FAQ on "How to make hotkeys context sensitive." I find the technique useful because it allows the easiest to reach/remember hotkeys to be "overloaded" with more functions: http://www.autohotkey.com/docs/FAQ.htm
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Wed Jun 30, 2004 9:07 am    Post subject: Reply with quote

beardboy wrote:

Yes, I have two compiled scripts that I use together. One is #Include'd in the other, and both have the ability to interact with the other by them storing variables in an INI file and checking the values on a regular basis.


Ok, #Include is fine, but how to unload?
Only way that I can see is to exit main script and start it again. Some alternative to that?

beardboy wrote:

You can setup multiple scripts or one big script and have multiple hotkeys. You can even setup hotkeys to do different things based on which windows exist or is currently active. It all just depends on what you want to do.


What I had in mind is something like this:
(not a real code, just some pseudo-something:)

Code:

OnStart, Word
{
  Word_Running = 1
}

OnStop, Word
{
  Word_Running = 0
}

IfEqual, Word_Running, 1
{
   Load "word.ahk"
}

IfEqual, Word_Running, 0
{
   UnLoad "word.ahk"
}



OnStart and OnStop should be triggered when programs start and exit (sorry but I don't know details how this can be done, maybe some internal loop which checks running progras).

Another idea is to bind some key to something like this:

Code:


F12::gosub, Word

Word:
IfWinNotActive, Word
{
   Run Word
        Word_Running = 1
   Load "word.ahk"
}
return


But detecting and unloading is hard, and it would not catch 'Word' when it is started by clicking on icon...

beardboy wrote:

Let me know if you needs some code examples for either of the above.


Please, attach some example if possbile :).
Thank you.
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed Jun 30, 2004 12:46 pm    Post subject: Reply with quote

If the app-sensitive behavior you want is not too complex, first ask yourself if you need any of your macros to be sensitive to the mere existence of an app. Most times, you're more interested in whether an app is currently the active window. If that is the case, this illustrates a typical approach:
Code:
SetTitleMatchMode, 2
return

#z::
IfWinActive, - Microsoft Word
{
     ... perform action for Word
     return
}
IfWinActive, Microsoft Excel -
{
    ... perform action for Excel
    return
}
; Since above didn't return, perform normal action (if any):
... normal actions for this hotkey.
return


In most cases, the above will allow you to have only a single script that does everything. If you need to detect whether an app is running, not just whether it is active, just replace IfWinActive with IfWinExist.

Depending on your needs, you might also find SetTimer useful to monitor the system. For example, a timer could monitor which apps are running and use the Hotkey command to disable or enable certain hotkeys accordingly.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   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