Jump to content

WinGetTitle and then switch to it as needed


Recommended Posts

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!
 
 

Link to comment
Share on other sites

  • 3 months later...

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
Link to comment
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.

Edited by TheSaint

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

Link to comment
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.

Link to comment
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 <<<<
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...