AutoHotkey Community

It is currently May 27th, 2012, 10:36 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: December 10th, 2007, 12:06 am 
Offline

Joined: December 9th, 2007, 11:46 pm
Posts: 19
Second Noob Q - & thanks for your patience...

I'd like to run a script ONCE after a program starts: eg Say I want to have typed "Welcome" each time Notepad is opened (not maximised, moved, made active but just each time a new Notepad instance is opened)

Thanks again
Nathan

EDIT - PS what I'm really try trying to do is work around a bug in PowerDVD where the mouse cursor is visible sometimes. Ideally I'd like to run
Code:
mousemove 2000,0
to simply get the mouse cursor pushed off the right hand side of the screen when PowerDVD first runs.


Last edited by jmone on December 10th, 2007, 1:35 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2007, 12:07 am 
Offline

Joined: November 1st, 2007, 10:03 pm
Posts: 885
that would be hard

you could create a notrayicon scripot that waits for notepad to be active then SendInput the text


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2007, 3:29 am 
Offline

Joined: June 27th, 2006, 2:38 pm
Posts: 385
Location: Canada
Hard? Pfft. Nah :)

Code:
#NoTrayIcon
#Persistent
#SingleInstance, Force

; Your window name goes here:
TargetWindow = Untitled - Notepad

Gui,+LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessages" )
return

ShellMessages( wParam,lParam )
{
   ;Local k
   global
   If (wParam = 1)
   {
      NewID := lParam
      WinGetTitle, Title, ahk_id %NewID%
      WinGetClass, Class, ahk_id %NewID%
      If Title =
      {
         sleep 2000
          WinGetTitle, Title, ahk_id %NewID%
          WinGetClass, Class, ahk_id %NewID%
      }
        If Title = %TargetWindow%
          gosub ActionLabel
      return 1
    }
}

ActionLabel:
SoundBeep
SoundBeep
SoundBeep
Msgbox Notepad has been detected!
return


Twas an interesting challenge. Cant remember where I got the info for shell hooks.. most likely [ Tips N Tricks: How to Hook on to Shell to receive its messages ]


Edit:
Don't know if you'll pick up on it yet, but theres a spot in the script where you can state a window name you want instead of "Untitled - Notepad" I marked it with "Your window name goes here:" above the line of code.
Also, at the bottom of the script, ActionLabel: is run every time a new notepad window is detected. So feel free to replace the sound beep's and msgbox with mousemove, send, or whatever your heart desires.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2007, 4:04 am 
Offline

Joined: December 9th, 2007, 11:46 pm
Posts: 19
Thanks - I'll give it a go this arvo. :D

How about the reverse - eg run a script when an applicaiton is closed and no longer exists!!!

Thanks
Nathan


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2007, 6:50 am 
Offline

Joined: December 9th, 2007, 11:46 pm
Posts: 19
Works great - more terrific community support for a very happy Newbie - :D

Thanks
Nathan

FYI the script picks up any instances of Notepad starting not just "Untitled" (eg opening up a script for editing sets it off as well)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 18th, 2007, 4:27 am 
Offline

Joined: December 17th, 2007, 1:52 am
Posts: 4
Since u guys seem to know much about window hooks etc!!!

Is there a way I can change the name of an active window......
The title bar text?

Thx


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2007, 12:18 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2250
Location: switzerland
WinSetTitle,existingtitle, ,newtitle


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, specter333 and 75 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