Sign in to follow this  
Followers 0
Yera

WinGetTitle and then switch to it as needed

11 posts in this topic

Hello, I am using 2 hotkeys in an au3 file: one to get the current window title. And the other to switch to that window as needed. Below is my code, which gives an error when I want to switch to the Window: " Error: Variable used withut being declared." 

#include <WinAPI.au3>
HotKeySet("^+g", "GetThisWinTitle")
HotKeySet("^+s", "SwitchToTheWindow")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func GetThisWinTitle()  ; 
 $sAppTitle = ( WinGetTitle(""))
 EndFunc 
Func SwitchToTheWindow() 
WinActivate($sAppTitle) 
EndFunc

Seems that the variable, $sAppTitle, is not available when I try call it to switch. Would appreciate any help. Many thanks!
 
 

Share this post


Link to post
Share on other sites



I think $sAppTitle is a local variable only present within your function that you set the value in (GetThisWinTitle). Try declaring $sAppTitle:

Global $sAppTitle

outside of your function declarations.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You don't need that first set of parentheses in line 7, and WinGetTitle is being used incorrectly also. See the example code (in the helpfile) for that function.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Great thanks! Global did the trick. Also, adjusted: $sAppTitle = WinGetTitle("")

All very best!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Sorry to revamp this thread, but it seemed appropriate as it is related.

Any idea how to switch to window that has variable title?

ie not always the same.

(To be precise, I wan't to create a snippet which would switch me to Kmplayer, but kmplayer has titles like "[5/5] Some_Movie.avi". ie. it uses what it currently plays as a title.)

Edited by Zch

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@Zch - It depends on how and where it is different. Window Title recognition has a few Modes, mentioned in the Help file.

For instance, the default Mode, recognizes letters from the start of the name, so if the first five don't change, just use them ... or something like that. You can also get a Handle for the first Window Title, and any subsequent renaming of that window title won't cause an issue, as the Handle will remain the same. I've used that last (a single instance/many page changes) with FireFox quite successfully.

Edited by TheSaint
1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@Zch - It depends on how and where it is different. Window Title recognition has a few Modes, mentioned in the Help file.

For instance, the default Mode, recognizes letters from the start of the name, so if the first five don't change, just use them ... or something like that. You can also get a Handle for the first Window Title, and any subsequent renaming of that window title won't cause an issue, as the Handle will remain the same. I've used that last (a single instance/many page changes) with FireFox quite successfully.

It changes completely, ie it always changes to the title of the video/audio file it's playing. except if I just start the program without loading playlist/video/audio, in which case I get "The KMPlayer" as windows title. 

I think it's good idea with using the windows handle. Must read more docs.

Thanks for the tip, I will post if I figure something out.

Share this post


Link to post
Share on other sites

here, I selected random video:

 

summary tab:

>>>> Window <<<<
Title: [34/329] Stargate SG-1 [2x03] Prisoners.avi
Class: Winamp v1.x
Position: 3727, 374
Size: 652, 434
Style: 0x96000000
ExStyle: 0x00010018
Handle: 0x0000000000020D94
 
>>>> Control <<<<
Class: TCustomPaintControl
Instance: 1
ClassnameNN: TCustomPaintControl1
Name:
Advanced (Class): [CLASS:TCustomPaintControl; INSTANCE:1]
ID: 11934312
Text:
Position: 6, 24
Size: 640, 360
ControlClick Coords: 117, 254
Style: 0x5E000000
ExStyle: 0x00010000
Handle: 0x0000000000B61A68
 
>>>> Mouse <<<<
Position: 3850, 652
Cursor ID: 2
Color: 0x010101
 
>>>> StatusBar <<<<
 
>>>> ToolsBar <<<<
 
>>>> Visible Text <<<<
 
 
>>>> Hidden Text <<<<

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0