AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: April 22nd, 2010, 11:05 am 
Hello. I'm a newbie and I have a very simple question. I'm creating a script should stay resident in memory. On of the things it should do is closing a specific window as soon as it appears on screen. Do I have to use Winwaitexist? But that will interrupt other functions? Do I have to use #persistent for that? Could you provide an example? Thankyou.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 11:07 am 
Offline

Joined: November 9th, 2009, 3:09 pm
Posts: 258
well put winwaitactive in a loop and define action once the window with that title exists


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 12:31 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
Please post your code.

In the meantime, carefully read up on WinWait, SetTimer and also the tips and tricks here.

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 5:18 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
You may be interested in WinTrigger.

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 8:54 pm 
Offline

Joined: April 22nd, 2010, 7:35 pm
Posts: 8
#Persistent
SetTimer, CloseUnwantedWindow, 250 ; checks every 250ms
Exit

CloseUnwantedWindow:
WinClose WhateverWindowNameYouWant
Return

~~~~~~~~~

I run this myself all the time and it works fine. Test it by opening Notepad and saving the Untitled file as the name specified in your script. It will close almost instantly.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 8:57 pm 
Offline

Joined: April 22nd, 2010, 7:35 pm
Posts: 8
By the way, I've only used the above script for a week or so after I needed to learn about timers. Prior to that I used a loop with WinWaitExist as the last part of a hotkey script I always have running. It was just as effective, but the version I just posted is much better, I believe, in that you can have many such timed subroutines running in your script while the script does other things. The WinWaitExist needs to be running in an infinite loop at the end of your auto-execute section, and is much more restrictive and inelegant.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 9:47 pm 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
920094519 wrote:
Code:
#Persistent
SetTimer, CloseUnwantedWindow, 250 ; checks every 250ms
Return ;Not Exit

CloseUnwantedWindow:
WinClose WhateverWindowNameYouWant
Return



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2010, 9:58 pm 
Offline

Joined: April 22nd, 2010, 7:35 pm
Posts: 8
Return or Exit, whichever makes sense in his script.

I gave him exactly what I use. Exit is at the end of the auto-execute portion of my script. The auto-execute section isn't a subroutine reached by gosub, etc., so Return doesn't make sense, although in that situation it works exactly like Exit, so no difference.

Anyway, no point cluttering up this thread with non-related discussion about Exit vs. Return. The 6-line script I posted works perfectly the way I posted it and it solves his problem.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2010, 1:19 pm 
920094519 wrote:
#Persistent
SetTimer, CloseUnwantedWindow, 250 ; checks every 250ms
Exit

CloseUnwantedWindow:
WinClose WhateverWindowNameYouWant
Return

~~~~~~~~~

I run this myself all the time and it works fine. Test it by opening Notepad and saving the Untitled file as the name specified in your script. It will close almost instantly.


Hi,

I am just getting started with autohotkey. I recorded a macro for searching a database application and exporting the results. I combined it with a list of account numbers that I need to search so that I have a script that will search for all of the account numbers. I will post the code below.

The only problem is that some of the account numbers do not exist in the database. If that is the case, I get a popup window saying "No documents found!"

Is the above solution going to work for me and if so, where do I put it in the script? Or do I need some other If command? This will occur right after the line
Code:
Send, 0002470242 MouseClick, left,  462,  631


Code:
WinWait, ReportXtender Viewer - [$$RX Database$$(READ ONLY) - 06/25/2002 RO],
IfWinNotActive, ReportXtender Viewer - [$$RX Database$$(READ ONLY) - 06/25/2002 RO], , WinActivate, ReportXtender Viewer - [$$RX Database$$(READ ONLY) - 06/25/2002 RO],
WinWaitActive, ReportXtender Viewer - [$$RX Database$$(READ ONLY) - 06/25/2002 RO],
MouseClick, left,  64,  39
Sleep, 100
MouseClick, left,  96,  78
Sleep, 100
MouseClick, left,  112,  567
Sleep, 100
Send, 0002470242
MouseClick, left,  462,  631
Sleep, 100
MouseClick, left,  124,  40
Sleep, 100
MouseClick, left,  220,  186
Sleep, 100
MouseClick, left,  360,  184
Sleep, 100
WinWait, Export Document Pages,
IfWinNotActive, Export Document Pages, , WinActivate, Export Document Pages,
WinWaitActive, Export Document Pages,
Send, u{SHIFTDOWN};{SHIFTUP}\bshipman\0002470242{ENTER}


Report this post
Top
  
Reply with quote  
 Post subject: Off topic
PostPosted: April 23rd, 2010, 5:00 pm 
Offline

Joined: April 22nd, 2010, 7:35 pm
Posts: 8
This is off topic. Please start a new thread. Post it under at the "Ask for Help" level, not as a reply to this post.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2010, 5:11 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
I don't think it is offtopic. He's asking how to close a window that /might/ pop up in that particular place of his code.

Since it's at a particular point in your script, I'd put a WinWait command using the "seconds" parameter, so it will check for it, but give up if it doesn't find the window. The problem there is that the waiting takes some time.

You could also use 920094519's solution.

Code:
;somewhere at the beginning of your script
SetTimer, CloseUnwantedWindow, 250 ; checks every 250ms
Return


;your normal script, unmodified
WinWait, ReportXtender Viewer - [$$RX Database$$(READ ONLY) - 06/25/2002 RO],
IfWinNotActive, ReportXtender Viewer - [$$RX Database$$(READ ONLY) - 06/25/2002 RO], , WinActivate, ReportXtender Viewer - [$$RX Database$$(READ ONLY) - 06/25/2002 RO],
WinWaitActive, ReportXtender Viewer - [$$RX Database$$(READ ONLY) - 06/25/2002 RO],
MouseClick, left,  64,  39
Sleep, 100
MouseClick, left,  96,  78
Sleep, 100
MouseClick, left,  112,  567
Sleep, 100
Send, 0002470242
MouseClick, left,  462,  631
Sleep, 100
MouseClick, left,  124,  40
Sleep, 100
MouseClick, left,  220,  186
Sleep, 100
MouseClick, left,  360,  184
Sleep, 100
WinWait, Export Document Pages,
IfWinNotActive, Export Document Pages, , WinActivate, Export Document Pages,
WinWaitActive, Export Document Pages,
Send, u{SHIFTDOWN};{SHIFTUP}\bshipman\0002470242{ENTER}


;somewhere at the very end of your script
CloseUnwantedWindow:
WinClose, , No documents found!
Return



WinClose might kill the whole program, though so instead you might want

Code:
CloseUnwantedWindow:
If WinExist("","No documents found!")
{
  WinActivate, , No documents found!
  Send, {enter}
}

Return

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2010, 8:25 pm 
Offline

Joined: April 23rd, 2010, 1:13 pm
Posts: 1
Sorry, didn't mean to clutter this thread. Just trying not to start a new thread if it was unnecessary.

Engunneer, when I use those two sets of commands as bookends around the script, I get an error message:

Error at line 47.

Line Text: CloseUnwantedWindow
Error: Duplicate label

The program will exit.


My entire script consists of the same 25 or so lines repeated, with a different account number in each set. I tried bookending each group of 25 lines with this and also putting the first part at the very beginning of the whole script and the second part at the very end, as I wasn't sure which way you were saying.

Any thoughts?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2010, 9:08 pm 
Offline

Joined: April 22nd, 2010, 7:35 pm
Posts: 8
Duplicate label seems pretty self-explanatory. How can AHK know where to go when you have the same label assigned to two places in the script? Each label must be unique.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: bowen666, MSN [Bot] and 16 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