Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Run Script on Program Load


  • Please log in to reply
10 replies to this topic
aahkuser
  • Members
  • 6 posts
  • Last active: May 07 2009 06:45 AM
  • Joined: 01 May 2009
I have several programs I open/use every day. Some days I shut the machine off, mostly I use Hibernate. When I open these programs, I now use keyboard shortcuts to (1) Maximize the screen, (2) go to a specific part of the program, and (3) open a prompt, etc.

I cannot figure out how to get AHK to recognize that a program (Microsoft Word for instance) just opened and when that program finishes loading, it runs a script. Can someone let me know if this is possible. I've searched the Community, and searched on Google without any luck.

Phaze
  • Members
  • 136 posts
  • Last active: Jan 23 2015 07:25 PM
  • Joined: 14 Sep 2007
Why not show us what you have already?

Also, we need to know what program (I know you said Word, but you also said for example), and what you want it to do.
Posted Image

aahkuser
  • Members
  • 6 posts
  • Last active: May 07 2009 06:45 AM
  • Joined: 01 May 2009
This is the example for a program I use at work. I need to (1) cancel a prompt window, (2) align the window to the top left, (3) re-size the program window, (4) press a button to view the main window.

This all works fine, but you requested the code, etc. The problem I have is that whenever I load the program (usually once a day, but some times several times) and it's annoying pressing the key combination each time. I want it to do this when the program is done loading, is it possible to have on_formload or something like that similar to Microsoft Access?

#IfWinActive Winworks AutoShop ahk_class #32770
	^!+d::
{
Send, n
Sleep, 275
WinGetPos, InitialWindowPosX, InitialWindowPosY, InitialWindowSizeX, InitialWindowSizeY
If InitialWindowPosX <> 0
{
	If InitialWindowPosY <> 0 
	{
WinMove, 0,0
	}
}
MouseClickDrag, Left, 100,749,100,769
Sleep, 100
MouseClick, left, 202, 78
}
return

(2) I have the same sort of thing randomly in Windows Media Player where it loads the "Now Playing" window and when the program loads, I want it to automatically do browser back.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
EDIT:
I have created a kind of template.
Hope it fits your needs.

EDIT: removed old code for "OnLoad/OnClose Script Template" by MasterFocus
Please see github.com/MasterFocus
Example 1 - Alerts when loaded and also closed
Example 2 - Alerts when loaded only
Example 3 - Alerts when closed only
Example 4 - Alerts when loaded only using a single "return"

=============================================================

Also, instead of
WinGetPos, InitialWindowPosX, InitialWindowPosY, InitialWindowSizeX, InitialWindowSizeY
If InitialWindowPosX <> 0
{
If InitialWindowPosY <> 0
{
WinMove, 0,0
}
}
you may try this:
WinGetPos, InitialWindowPosX, InitialWindowPosY
If InitialWindowPosX AND InitialWindowPosY
WinMove, 0,0
(don't know if you're using InitialWindowPos, but seems unnecessary)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Nice work, MasterFocus. I've made a few tweaks:
; Original script by MasterFocus. See original post for instructions.
EDIT: code removed - please see github.com/MasterFocus for up-to-date code
Notable differences:
- Shorter. wink.png
- Less dynamic variable references. This should prove a little more efficient.
- OnOpen instead of OnLoad. I figure "Open" more naturally opposes "Close".
- OnOpen can be defined without OnClose, and vice versa.

aahkuser
  • Members
  • 6 posts
  • Last active: May 07 2009 06:45 AM
  • Joined: 01 May 2009
Thanks a lot. This is take some time to go through, lol. But it looks like its exactly what I need.

Also, I have been looking for an Intellisense editor for AHK (more or less a copy of the VBA editor in M-Office). Does anyone have a recommendation?

lilalurl.T32
  • Members
  • 391 posts
  • Last active: Jul 05 2011 03:39 PM
  • Joined: 17 May 2007

Also, I have been looking for an Intellisense editor for AHK (more or less a copy of the VBA editor in M-Office). Does anyone have a recommendation?


Something like that?
<!-- m -->http://www.autohotke...opic.php?t=1371<!-- m -->
________
WASHINGTON MEDICAL MARIJUANA DISPENSARY

aahkuser
  • Members
  • 6 posts
  • Last active: May 07 2009 06:45 AM
  • Joined: 01 May 2009
I'll have to look at the thread more, but I don't think it's enough, because I also need to be exactly like VBA in that it makes "; comments" green (or some color), reminds me to close a bracket, in addition to the auto-complete.

I looked at the AHK Editor and one another one, but didn't find them similar at all and have just been using Notepad from then on.

bqw371
  • Members
  • 32 posts
  • Last active: Nov 16 2010 01:38 AM
  • Joined: 26 Nov 2008

Also, I have been looking for an Intellisense editor for AHK (more or less a copy of the VBA editor in M-Office). Does anyone have a recommendation?


Is this what you are looking for?
Posted Image

http://www.autohotke...topic41503.html

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Lexikos, you pointed out some interesting things I did not know.
Thanks for the modifications.

pajenn
  • Members
  • 391 posts
  • Last active: Feb 06 2015 07:57 AM
  • Joined: 07 Feb 2009
I use Bill2's Process Manager to control priorities and affinities. It has the option to launch side programs when the desired process starts or ends ans since I'm running it anyway, I use it to launch similar add-on scripts that you described. The program would be overkill for script launching alone, but I'd recommend it to anyone who is also looking for priotity and affinity management for a multi-core machine.

Warning: To be useful, Bill2 needs to be run in learning mode at first, which consists of lots of pop ups each time a new process is detected asking if you want to set a rule for it. The pop ups are annoying, but once you have Bill2 set up, it can be of great value.

Hardware: fast laptop with SSD
Software: Win 7 Home Premium 64-bit, android for phone and tablet