kjpolker Posted July 3, 2011 Share Posted July 3, 2011 I have a simple request as I have not touched Autoit in several months (about a year) and I was asked to try and come up with a program for a buddy. As part of the script I need to set a hot key to execute an alt+tab. I know I can use WinActivate but I prefer not to work with window titles. I am sure there is an easier was I may be overlooking. I couldn't find anything in the help file mainly because I am not sure a fancy name for switching between windows. Please let me know what I need to achieve this! Link to comment Share on other sites More sharing options...
Developers Jos Posted July 3, 2011 Developers Share Posted July 3, 2011 you want a hotkey to Send Alt+Tab for you so why not simply do just that? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kjpolker Posted July 3, 2011 Author Share Posted July 3, 2011 (edited) Hmm. Touche! Will do I assume I need to have some sort of a while loop so the program doesn't just run through and close. What should I have the while loop doing though? Currently this is what I have Local $Key HotKeySet($Key, "Toggle") $Key = IniRead(@ScriptDir & "Config.ini", "KEY", "Key", "") Func Toggle() Send("!{TAB}") EndFunc Edited July 3, 2011 by kjpolker Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 3, 2011 Share Posted July 3, 2011 Ya I guess it has been quite a while.. Read the Example, HotKeySet. - 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...
Maffe811 Posted July 3, 2011 Share Posted July 3, 2011 Add a While 1 Sleep(40) Wendto the bottom [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
kjpolker Posted July 3, 2011 Author Share Posted July 3, 2011 Okay all good on that. Now I ran into another problem, I have an IniRead in my script, I want it to MsgBox if there is a blank in the Ini file, but continue on if not. Example: $Key = IniRead( @ScriptDir & "\Config.ini", "KEY", "Key", "") If $Key = "" Then MsgBox(0, "Message", "Wait! No key has been set in Config.ini") ShellExecute( @ScriptDir & "\Config.ini") Exit I assume that by using "" in the IfElse statement it reads the blank as being any key, so even if I put a key into the ini file this message still pops up. Isn't there a way to indicate a space? Or would that not work either? Link to comment Share on other sites More sharing options...
Developers Jos Posted July 3, 2011 Developers Share Posted July 3, 2011 Okay all good on that. Now I ran into another problem, I have an IniRead in my script, I want it to MsgBox if there is a blank in the Ini file, but continue on if not. Example: $Key = IniRead( @ScriptDir & "\Config.ini", "KEY", "Key", "") If $Key = "" Then MsgBox(0, "Message", "Wait! No key has been set in Config.ini") ShellExecute( @ScriptDir & "\Config.ini") Exit I assume that by using "" in the IfElse statement it reads the blank as being any key, so even if I put a key into the ini file this message still pops up. Isn't there a way to indicate a space? Or would that not work either? Look at your IF ... its a one line IF so only that line is conditional and the rest will always be executed. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kjpolker Posted July 3, 2011 Author Share Posted July 3, 2011 (edited) So I use a If...Then...ElseIf...Then? If $Key = "" Then MsgBox(0, "Message", "Wait! No key has been set in Config.ini") ShellExecute( @ScriptDir & "\Config.ini") Exit Else Func Toggle() EndIf EndIf Gives me the error "If" statement has no matching "EndIf" statement!But I do have an EndIf... Edited July 3, 2011 by kjpolker Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 3, 2011 Share Posted July 3, 2011 Maybe this'll work - change the default in IniRead to "NoKey" or something like that. Then check if $key equals whatever you set the default to be. - 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...
somdcomputerguy Posted July 3, 2011 Share Posted July 3, 2011 @Jos - Oops, I didn't catch the one line If.. @ kjpolker - If you want to execute the Toggle() function, just call it like this "Toggle()", not "Func Toggle". That's where the 'No Matching' error is coming from. - 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...
Developers Jos Posted July 3, 2011 Developers Share Posted July 3, 2011 So I use a If...Then...ElseIf...Then? If $Key = "" Then MsgBox(0, "Message", "Wait! No key has been set in Config.ini") ShellExecute( @ScriptDir & "\Config.ini") Exit Else Func Toggle() EndIf EndIf Gives me the error But I do have an EndIf... You have a FUNC statement in there which you do not want and an EndIf. Please be a little patient and do some checking before posting each and every time you have a little mistake or setback. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kjpolker Posted July 3, 2011 Author Share Posted July 3, 2011 Well I wanted to leave it blank to make it fail proof and screwing up the script. I got it now though, it was the Func that screwed it up so thank you! I ended up with Global $Key $Key = IniRead( @ScriptDir & "\Config.ini", "KEY", "Key", "`") HotKeySet($Key, "Toggle") If $Key = "" Then MsgBox(0, "Message", "Wait! No key has been set in Config.ini") ShellExecute( @ScriptDir & "\Config.ini") Exit Else Toggle() EndIf While 1 ToolTip("Program is running") Sleep(100) WEnd Func Toggle() Send("!{TAB}") EndFunc If you were curious. Link to comment Share on other sites More sharing options...
Maffe811 Posted July 4, 2011 Share Posted July 4, 2011 (edited) Fixed the problems and fixed the annoying tooltip#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Global $Key Opt("WinTitleMatchMode",2) $Key = IniRead(@ScriptDir & "\Config.ini", "KEY", "Key", "Blank") If $Key = "Blank" Then IniWrite(@ScriptDir & "\Config.ini", "KEY", "Key", "Blank") ;The two lines below and the first wwhile loop could be replaced with an inputbox. MsgBox(0, "Message", "Wait! No key has been set in Config.ini") ShellExecute(@ScriptDir & "\Config.ini") EndIf Sleep(500) While WinExists ("Notepad") Sleep(100) Wend $Key = IniRead(@ScriptDir & "\Config.ini", "KEY", "Key", "Blank") HotKeySet($Key, "Toggle") TrayTip("Program","Program is running",100,1) While 1 Sleep(100) WEnd Func Toggle() Send("!{TAB}") EndFunc ;==>Toggle Edited July 4, 2011 by Maffe811 [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] 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