 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
rainsux
Joined: 03 Nov 2009 Posts: 5 Location: KPTK
|
Posted: Wed Nov 04, 2009 7:31 pm Post subject: Foreground/Focus Problem |
|
|
I'm a newbie to AHK - not a newbie to programming.
I've used the search feature and browsed the tutorials,
but not found a crisp post re: focus (foreground).
My first script works until another window grabs focus
(becomes the foreground window) .... typically a
status/upgrade/nag window of some sort.
My attempts to use SetTitleMatchMode and WinActive
are not changing focus (bringing Mozilla back to the
foreground).
Help, please.
| Code: | SetTitleMatchMode, 2
Loop {
Run http://www.google.com/
Sleep, 10000
WinActivate, Mozilla
Send, {TAB}{ENTER}
Sleep, 10000
WinActivate, Mozilla
Send, !f
Sleep, 5000
WinActivate, Mozilla
Send, x
Sleep, 1000000
} |
-doug _________________ I spend 80% of my money on airplanes and
beer, the rest is wasted. |
|
| Back to top |
|
 |
txquestor
Joined: 22 Aug 2009 Posts: 294
|
Posted: Wed Nov 04, 2009 8:16 pm Post subject: |
|
|
Check out
WinSet, AlwaysOnTop
And
Last Found Window _________________
"Man's quest for knowledge is an expanding series whose limit is infinity" |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 1158 Location: San Diego, California
|
Posted: Wed Nov 04, 2009 9:40 pm Post subject: |
|
|
| Quote: | | I'm a newbie to AHK - not a newbie to programming. |
Why do you have 5 seconds delay between alt-F and x ?
Since you are a programmer you know you start with simple routines and build upon them.
So, if you'll bear with me, I have a few basic questions.
Please confirm: is the word "Mozilla" always in the browser title?
For example my current browser window has exactly:"Post a reply - Windows Internet Explorer"
Please confirm: is the word "Mozilla" EVER in the 'status/upgrade/nag ' ?
Run the following code, run your browser steps manually.
When the browser looses focus, does running this hotkey routine ALWAYS "bring it back to top/focus"?
If not 100%, what is the title of the window that has top/focus?
| Code: | SetTitleMatchMode, 2
return
F1:: ;<-------------------I chose the F1 hotkey, change as desired
WinActivate, Mozilla
return |
|
|
| Back to top |
|
 |
rainsux
Joined: 03 Nov 2009 Posts: 5 Location: KPTK
|
Posted: Thu Nov 05, 2009 1:21 pm Post subject: |
|
|
Why do you have 5 seconds delay between alt-F and x ?
> Eases my task of monitoring AHK behavior to close Mozilla
Since you are a programmer you know you start with simple routines and build upon them.
> Yup. Which is why I began with a simple
> infinite loop with simple timers. The simple
> AHK script works ... until another window
> pops-up and steals focus.
So, if you'll bear with me, I have a few basic questions.
Please confirm: is the word "Mozilla" always in the browser title?
> Confirmed. Since I'm using "SetTitleMatchMode, 2" ... I am
> expecting that any window with "Mozilla" anywhere in the title
> should be a match ... for the subsequent; "WinSet, AlwaysOnTop, On, Mozilla"
For example my current browser window has exactly:"Post a reply - Windows Internet Explorer"
> I'm using Mozilla, not "Windows Internet Explorer"
Please confirm: is the word "Mozilla" EVER in the 'status/upgrade/nag ' ?
> To my knowledge, never. Haven't seen it yet.
Run the following code, run your browser steps manually.
When the browser looses focus, does running this hotkey routine ALWAYS "bring it back to top/focus"?
> It depends ...
>
> Since my AHK script is an infinite loop; the next
> pass thru the loop should close Mozilla ... and it
> does close Mozilla unless another has pop'd and
> stolen focus during one of the sleep's.
>
> If I kill AHK and restart it ... Mozilla will [re]grab
> focus. The loop will continue to execute until the
> next status/update/nag screen pops (and steals
> focus).
If not 100%, what is the title of the window that has top/focus?
> Pretty much any window can steal focus. I can provoke it by
> having a "Command Prompt" window open; or "GVIM"; or "Excel";
> or "bash"; or any of goofy balloon status dialogs that appear from the
> task bar. Last night it was a Sun Java updates-are-available dialog
> that stole focus.
Here is the latest edition that still has the (loss of) focus behavior:
SetTitleMatchMode, 2
WinSet, AlwaysOnTop, On, Mozilla
Loop {
Run http://www.google.com
Sleep, 1000
Send, {TAB}{ENTER}
Sleep, 10000
Send, !f
Sleep, 5000
Send, x
Sleep, 1000000
} _________________ I spend 80% of my money on airplanes and
beer, the rest is wasted. |
|
| Back to top |
|
 |
OceanMachine
Joined: 15 Oct 2007 Posts: 138
|
Posted: Thu Nov 05, 2009 1:49 pm Post subject: |
|
|
What are you actually trying to achieve?
The focusing is working fine for me as per your first script, although if focus changes between your "Alt-F" and "X" then the file menu will be closed when the focus is lost, meaning that your "X" key will be sent to the google window, not the menu. Other than that, I can wait for the first command, change focus, and the "Alt-F" command has focus brought back to the Mozilla window fine for me.
If you specify what you are actually trying to do, then we can find a more reliable way of doing it for you (because of the above problems). |
|
| Back to top |
|
 |
rainsux
Joined: 03 Nov 2009 Posts: 5 Location: KPTK
|
Posted: Thu Nov 05, 2009 3:03 pm Post subject: |
|
|
> what are you trying to do?
Specifically; ALT-F and x, are simply the commands to politely close
Mozilla.
I *ass*umed that WinSet, AlwaysOnTop did precisely that. ALWAYS,
On-top ... and that I only needed to set it once (outside the infinite loop).
Should I be calling it after the "run http://www.google.com" that starts
Mozilla?
Should I be setting it after every call to SLEEP?
Or; perhaps I need to be calling WinActivate after the WinSet?
On a broader scope; I am attempting to script an "Agree" button on a
T&C/splash page that the netw admin has setup with an absurdly short
(15 minute) expiration.
The AHK script does that task ("Agree") ... but works only if focus is not
stolen from Mozilla.
Since I'm missing something about AHK and focus/foreground (or AHK is
broken?), I'm beginning to think about using my bag o'hammers ... and
using Run TASKKILL to bludgeon all instances of firefox.exe. Admittedly,
a truely crude approach. <g> But it also solves the problem of what-if
firefox.exe has children, or if there are multiple copies of firefox.exe
running. Hmmmh. _________________ I spend 80% of my money on airplanes and
beer, the rest is wasted. |
|
| Back to top |
|
 |
OceanMachine
Joined: 15 Oct 2007 Posts: 138
|
Posted: Thu Nov 05, 2009 3:26 pm Post subject: |
|
|
Yes, as you can't set a window to always be on top until it actually exists.
Additionally, just because the window is "Always ON TOP" does not mean that it "Always HAS FOCUS"
| rainsux wrote: | | Specifically; ALT-F and x, are simply the commands to politely close Mozilla. |
Indeed they are, but I was trying to establish the reason for the 5 second pause between the Alf-F and X? Have you tried just doing :
Also, you can just use WinClose or WinKill instead:
| Code: | WinClose, Mozilla ; less forceful
WinKill, Mozilla ; more forceful |
Or if you want to be more specific, you can input the title of the specific page you want to close, and that will leave other instances of Mozilla open (rather than using the 'catch-all' word of 'Mozilla' in your window title).
I'm not sure if the below works any better for you?
| Code: |
SetTitleMatchMode, 2
Loop {
Run http://www.google.com
WinWait, Google
WinSet, AlwaysOnTop, On, Google
WinActivate
Sleep, 10000
WinActivate
Send, {TAB}{ENTER}
Sleep, 10000
WinKill, Google
Sleep, 1000000
}
|
EDIT: Just added the extra WinActivate before you send the TAB and ENTER (forgot that initially, sorry)...
Last edited by OceanMachine on Thu Nov 05, 2009 7:32 pm; edited 1 time in total |
|
| Back to top |
|
 |
rainsux
Joined: 03 Nov 2009 Posts: 5 Location: KPTK
|
Posted: Thu Nov 05, 2009 4:09 pm Post subject: |
|
|
> Have you tried just doing: Send, !fx
Yes. Works okay. The delay was simply an artifact from my initial
attempts ... it allowed me to more easily watch what was happening.
I'll take your suggestion to use WinKill ... it solves all the problems of
other possible Mozilla instances and/or their children. _________________ I spend 80% of my money on airplanes and
beer, the rest is wasted. |
|
| Back to top |
|
 |
OceanMachine
Joined: 15 Oct 2007 Posts: 138
|
Posted: Thu Nov 05, 2009 7:34 pm Post subject: |
|
|
| Just added the extra WinActivate before the TAB and ENTER line, as of course during the previous 10 seconds sleep the focus may have been lost! Sorry, forgot to add that initially. |
|
| Back to top |
|
 |
rainsux
Joined: 03 Nov 2009 Posts: 5 Location: KPTK
|
Posted: Thu Nov 05, 2009 8:22 pm Post subject: |
|
|
Thanks ... I'd guessed that was appropriate. Nice to know my hunch
was correct. _________________ I spend 80% of my money on airplanes and
beer, the rest is wasted. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|