Yera Posted May 23, 2013 Share Posted May 23, 2013 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 More sharing options...
lingo124 Posted May 23, 2013 Share Posted May 23, 2013 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. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 23, 2013 Share Posted May 23, 2013 (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 May 23, 2013 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Yera Posted May 23, 2013 Author Share Posted May 23, 2013 Great thanks! Global did the trick. Also, adjusted: $sAppTitle = WinGetTitle("") All very best! Link to comment Share on other sites More sharing options...
Zch Posted September 21, 2013 Share Posted September 21, 2013 (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 September 21, 2013 by Zch Link to comment Share on other sites More sharing options...
TheSaint Posted September 21, 2013 Share Posted September 21, 2013 (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 September 21, 2013 by TheSaint Zch 1 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) Link to comment Share on other sites More sharing options...
Zch Posted September 24, 2013 Share Posted September 24, 2013 @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 More sharing options...
JohnOne Posted September 24, 2013 Share Posted September 24, 2013 You can find it by it's class. Post the info of summary tab, from window info tool. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Zch Posted September 27, 2013 Share Posted September 27, 2013 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 More sharing options...
JohnOne Posted September 27, 2013 Share Posted September 27, 2013 WinActivate("[Class:Winamp v1.x]") AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Zch Posted September 28, 2013 Share Posted September 28, 2013 Thank you a lot Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now